-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from pagopa/IOPLT-337-creating-system-tests-fo…
…r-query-cosmos-enrichment [IOPLT-337] Creating system tests for query cosmos enrichment
- Loading branch information
Showing
9 changed files
with
2,785 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
module.exports = { | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
env: { | ||
es6: true, | ||
node: true, | ||
jasmine: true, | ||
jest: true | ||
}, | ||
"ignorePatterns": [ | ||
"node_modules", | ||
"generated", | ||
"**/__tests__/*", | ||
"**/__mocks__/*", | ||
"*.d.ts", | ||
"*.js", | ||
"Dangerfile.ts" | ||
ignorePatterns: [ | ||
"node_modules", | ||
"generated", | ||
"**/__tests__/*", | ||
"**/__mocks__/*", | ||
"*.d.ts", | ||
"*.js", | ||
"Dangerfile.ts", | ||
"**/__integrations__/utils", | ||
"**/__integrations__/env.ts", | ||
"index.ts" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": "./tsconfig.json", | ||
"sourceType": "module" | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: "./tsconfig.json", | ||
sourceType: "module" | ||
}, | ||
"extends": [ | ||
"@pagopa/eslint-config/strong", | ||
], | ||
"rules": {} | ||
extends: ["@pagopa/eslint-config/strong"], | ||
rules: {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
__integrations__/__tests__/system/cosmos/queryenrichment.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { CosmosClient } from "@azure/cosmos"; | ||
import * as O from "fp-ts/Option"; | ||
import * as TE from "fp-ts/lib/TaskEither"; | ||
import { pipe } from "fp-ts/lib/function"; | ||
import { createCosmosQueryEnrichmentService } from "../../../../src/enrichment/query/cosmos/service"; | ||
import { COSMOSDB_CONNECTION_STRING, COSMOSDB_NAME } from "../../../env"; | ||
import { | ||
COLLECTION_ID, | ||
COLLECTION_ID_KEY, | ||
COLLECTION_ID_VERSION, | ||
COLLECTION_PARTITION_KEY, | ||
COLLECTION_PARTITION_KEY_VALUE, | ||
COSMOS_COLLECTION_NAME, | ||
VERSION_FIELD_NAME, | ||
VERSION_FIELD_VALUE, | ||
WRONG_VERSION_FIELD_VALUE, | ||
createCosmosDbAndCollections, | ||
deleteDatabase, | ||
} from "../../../utils/cosmos"; | ||
|
||
const client = new CosmosClient(COSMOSDB_CONNECTION_STRING); | ||
|
||
beforeAll(async () => { | ||
await pipe( | ||
createCosmosDbAndCollections(client, COSMOSDB_NAME), | ||
TE.getOrElse((e) => { | ||
throw Error( | ||
`Cannot initialize integration tests - ${JSON.stringify(e.message)}`, | ||
); | ||
}), | ||
)(); | ||
}, 60000); | ||
|
||
afterAll(async () => { | ||
await pipe( | ||
deleteDatabase(client, COSMOSDB_NAME), | ||
TE.getOrElse((e) => { | ||
throw Error(`Cannot delete db ${e.message}`); | ||
}), | ||
)(); | ||
}); | ||
|
||
describe("findByKey", () => { | ||
it("should return Some(unknown) when the item is found", async () => { | ||
await pipe( | ||
createCosmosQueryEnrichmentService(COSMOSDB_CONNECTION_STRING), | ||
TE.fromEither, | ||
TE.chain((service) => | ||
service.findByKey( | ||
COSMOSDB_NAME, | ||
COSMOS_COLLECTION_NAME, | ||
COLLECTION_ID_KEY, | ||
COLLECTION_PARTITION_KEY, | ||
), | ||
), | ||
TE.bimap( | ||
(err) => { | ||
new Error( | ||
`it should not fail while finding an existing document - ${err.message}`, | ||
); | ||
}, | ||
O.fold( | ||
() => { | ||
throw new Error("it should be some"); | ||
}, | ||
(result) => | ||
expect(result).toMatchObject({ | ||
id: COLLECTION_ID_KEY, | ||
key: COLLECTION_PARTITION_KEY, | ||
}), | ||
), | ||
), | ||
)(); | ||
}); | ||
|
||
it("should return None when the item is not found - find by id and partition key", async () => { | ||
await pipe( | ||
createCosmosQueryEnrichmentService(COSMOSDB_CONNECTION_STRING), | ||
TE.fromEither, | ||
TE.chain((service) => | ||
service.findByKey( | ||
COSMOSDB_NAME, | ||
COSMOS_COLLECTION_NAME, | ||
COLLECTION_ID, | ||
COLLECTION_PARTITION_KEY, | ||
), | ||
), | ||
TE.bimap( | ||
(err) => { | ||
new Error( | ||
`it should not fail while finding an existing document - ${err.message}`, | ||
); | ||
}, | ||
(result) => expect(O.isNone(result)).toBeTruthy(), | ||
), | ||
)(); | ||
}); | ||
}); | ||
|
||
describe("findByLastVersionKey", () => { | ||
it("should return Some(unknown) when the item is found with the last version", async () => { | ||
return await pipe( | ||
createCosmosQueryEnrichmentService(COSMOSDB_CONNECTION_STRING), | ||
TE.fromEither, | ||
TE.chain((service) => | ||
service.findLastVersionByKey( | ||
COSMOSDB_NAME, | ||
COSMOS_COLLECTION_NAME, | ||
VERSION_FIELD_NAME, | ||
VERSION_FIELD_VALUE, | ||
COLLECTION_ID_VERSION, | ||
COLLECTION_PARTITION_KEY, | ||
COLLECTION_PARTITION_KEY_VALUE, | ||
), | ||
), | ||
TE.bimap( | ||
(err) => { | ||
new Error( | ||
`it should not fail while finding an existing document - ${err.message}`, | ||
); | ||
}, | ||
O.fold( | ||
() => { | ||
throw new Error("it should be some"); | ||
}, | ||
(result) => { | ||
expect(result).toMatchObject({ | ||
id: COLLECTION_ID_VERSION, | ||
key: COLLECTION_PARTITION_KEY_VALUE, | ||
version: VERSION_FIELD_VALUE, | ||
}); | ||
}, | ||
), | ||
), | ||
)(); | ||
}); | ||
|
||
it("should return None(unknown) when the item is not found with the specific version", async () => { | ||
await pipe( | ||
createCosmosQueryEnrichmentService(COSMOSDB_CONNECTION_STRING), | ||
TE.fromEither, | ||
TE.chain((service) => | ||
service.findLastVersionByKey( | ||
COSMOSDB_NAME, | ||
COSMOS_COLLECTION_NAME, | ||
VERSION_FIELD_NAME, | ||
WRONG_VERSION_FIELD_VALUE, | ||
COLLECTION_ID_KEY, | ||
COLLECTION_PARTITION_KEY, | ||
COLLECTION_PARTITION_KEY_VALUE, | ||
), | ||
), | ||
TE.bimap( | ||
(err) => { | ||
new Error( | ||
`it should not fail while finding an existing document - ${err.message}`, | ||
); | ||
}, | ||
(result) => expect(O.isNone(result)).toBeTruthy(), | ||
), | ||
)(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as dotenv from "dotenv"; | ||
|
||
dotenv.config({ path: "./environments/.env" }); | ||
|
||
export const COSMOSDB_URI = process.env.COSMOSDB_URI; | ||
export const COSMOSDB_KEY = process.env.COSMOSDB_KEY; | ||
export const COSMOSDB_CONNECTION_STRING = | ||
process.env.COSMOSDB_CONNECTION_STRING ?? "COSMOSDB_CONNECTION_STRING"; | ||
export const COSMOSDB_NAME = process.env.COSMOSDB_NAME ?? "db"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@pagopa/change-data-capturer-integrations", | ||
"version": "1.0.0", | ||
"description": "Integration test suite for integration testing", | ||
"license": "MIT", | ||
"keywords": [], | ||
"author": "", | ||
"scripts": { | ||
"start": "docker-compose up -d", | ||
"stop": "docker-compose down", | ||
"build": "tsc", | ||
"test": "jest --runInBand" | ||
}, | ||
"dependencies": { | ||
"@azure/cosmos": "^4.0.0", | ||
"dotenv": "^16.3.1", | ||
"fp-ts": "^2.16.1" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.11", | ||
"@types/node": "^20.10.6", | ||
"dotenv-cli": "^7.3.0", | ||
"jest": "^29.7.0", | ||
"prettier": "^3.1.1", | ||
"ts-jest": "^29.1.1", | ||
"typescript": "^5.3.3" | ||
}, | ||
"jest": { | ||
"preset": "ts-jest", | ||
"collectCoverage": false, | ||
"testEnvironment": "node", | ||
"testPathIgnorePatterns": [ | ||
"dist", | ||
"/node_modules" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"target": "es6", | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"outDir": "dist", | ||
"baseUrl": ".", | ||
"paths": { | ||
"*": [ | ||
"node_modules/*", | ||
"src/types/*" | ||
] | ||
}, | ||
}, | ||
"references": [ | ||
{ | ||
"path": "..", | ||
} | ||
], | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} |
Oops, something went wrong.