Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IOPLT-337] Creating system tests for query cosmos enrichment #27

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions .eslintrc.js
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: {}
};
16 changes: 15 additions & 1 deletion .github/workflows/code-review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
timeout-minutes: 10 # temp fix
runs-on: ubuntu-latest

environment: IntegrationTests

steps:
- name: Check out code
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab #v3.5.2
Expand All @@ -43,4 +45,16 @@ jobs:
${{ runner.os }}-turbo-

- name: 'Code review'
run: yarn run code-review
run: yarn run code-review

- name: Set env
run: |
echo "NODE_TLS_REJECT_UNAUTHORIZED=0" >> $GITHUB_ENV
echo "COSMOSDB_NAME=${{github.run_id}}" >> $GITHUB_ENV
echo "COSMOSDB_CONNECTION_STRING=${{secrets.COSMOSDB_CONNECTION_STRING}}" >> $GITHUB_ENV

- name: System tests
run: |
cd __integrations__
yarn install --immutable
yarn test
163 changes: 163 additions & 0 deletions __integrations__/__tests__/system/cosmos/queryenrichment.test.ts
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");
drmarro marked this conversation as resolved.
Show resolved Hide resolved
},
(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}`,
drmarro marked this conversation as resolved.
Show resolved Hide resolved
);
},
O.fold(
() => {
throw new Error("it should be some");
drmarro marked this conversation as resolved.
Show resolved Hide resolved
},
(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}`,
drmarro marked this conversation as resolved.
Show resolved Hide resolved
);
},
(result) => expect(O.isNone(result)).toBeTruthy(),
),
)();
});
});
9 changes: 9 additions & 0 deletions __integrations__/env.ts
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";
37 changes: 37 additions & 0 deletions __integrations__/package.json
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"
]
}
}
27 changes: 27 additions & 0 deletions __integrations__/tsconfig.json
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/**/*"
]
}
Loading
Loading