Skip to content

Commit

Permalink
fix system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AleDore committed Mar 18, 2024
1 parent ae05d50 commit 8cd41ab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 41 deletions.
68 changes: 29 additions & 39 deletions __integrations__/__tests__/system/cosmos/queryenrichment.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
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 { constVoid, 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";
import {
IKeyQueryEnrichmentParams,
IVersionedQueryEnrichmentParams,
} from "../../../../src/utils/types";

const client = new CosmosClient(COSMOSDB_CONNECTION_STRING);

Expand All @@ -35,24 +37,24 @@ afterAll(async () => {
await pipe(
deleteDatabase(client, COSMOSDB_NAME),
TE.getOrElse((e) => {
throw Error(`Cannot delete db ${e.message}`);
throw Error(`Cannot delete db ${e}`);
}),
)();
});

const findByKeyParams: IKeyQueryEnrichmentParams<Record<string, unknown>> = {
containerName: COSMOS_COLLECTION_NAME,
databaseName: COSMOSDB_NAME,
idFieldValue: COLLECTION_ID_KEY,
partitionKeyFieldValue: COLLECTION_PARTITION_KEY,
};

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.chain((service) => service.findByKey(findByKeyParams)),
TE.bimap(
(err) => {
new Error(
Expand All @@ -77,14 +79,7 @@ describe("findByKey", () => {
await pipe(
createCosmosQueryEnrichmentService(COSMOSDB_CONNECTION_STRING),
TE.fromEither,
TE.chain((service) =>
service.findByKey(
COSMOSDB_NAME,
COSMOS_COLLECTION_NAME,
COLLECTION_ID,
COLLECTION_PARTITION_KEY,
),
),
TE.chain((service) => service.findByKey({...findByKeyParams, idFieldValue: Math.random().toString()})),
TE.bimap(
(err) => {
new Error(
Expand All @@ -97,21 +92,24 @@ describe("findByKey", () => {
});
});

const findLastVersionParams: IVersionedQueryEnrichmentParams<
Record<string, unknown>
> = {
containerName: COSMOS_COLLECTION_NAME,
databaseName: COSMOSDB_NAME,
idFieldValue: COLLECTION_ID_VERSION,
partitionKeyFieldName: COLLECTION_PARTITION_KEY,
partitionKeyFieldValue: COLLECTION_PARTITION_KEY_VALUE,
versionFieldName: VERSION_FIELD_NAME,
};

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,
),
service.findLastVersionByKey(findLastVersionParams),
),
TE.bimap(
(err) => {
Expand All @@ -135,20 +133,12 @@ describe("findByLastVersionKey", () => {
)();
});

it("should return None(unknown) when the item is not found with the specific version", async () => {
it("should return None(unknown) when the item is not found with last 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,
),
service.findLastVersionByKey({...findLastVersionParams, idFieldValue: Math.random().toString()}),
),
TE.bimap(
(err) => {
Expand Down
5 changes: 3 additions & 2 deletions src/filtering/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const filterStatic = <
staticValue?: K
) => (input: T): E.Either<Error, boolean> =>
pipe(
{ condition, fieldName, staticValue },
{ condition, fieldName, filterType: "STATIC", staticValue },
DataFilter.decode,
E.mapLeft(() => new Error("Wrong Filter Definition")),
E.chain(_ =>
Expand All @@ -61,7 +61,8 @@ export const filterDynamic = <
{
compareField,
condition,
fieldName
fieldName,
filterType: "DYNAMIC"
},
DataFilter.decode,
E.mapLeft(errors => new Error(errors.map(e => e.message).join("\n"))),
Expand Down

0 comments on commit 8cd41ab

Please sign in to comment.