Skip to content

Commit

Permalink
[#IP-342] update utils/__tests__/types.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
gquadrati committed Sep 3, 2021
1 parent d39eca8 commit e183859
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions utils/__tests__/types.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { readableReport } from "@pagopa/ts-commons/lib/reporters";
import { pipe } from "fp-ts/lib/function";
import {
DisjoitedNotificationHubPartitionArray,
NotificationHubPartition,
RegExpFromString
} from "../types";

import * as E from "fp-ts/lib/Either";

beforeEach(() => {
jest.clearAllMocks();
});
Expand All @@ -26,15 +29,19 @@ describe("nhDisjoitedFirstCharacterPartitionReadonlyArray", () => {
aGapedPartition
] = [aRegex, aComplementaryRegex, anOverlappingRegex, aGapedRegex].map(
(partitionRegex, i) =>
NotificationHubPartition.decode({
name: `partition${i}`,
partitionRegex,
endpoint: "an endpoint"
}).getOrElseL(e =>
fail(
`Cannot decode NotificationHubPartitions, i: ${i} error: ${readableReport(
e
)}`
pipe(
{
name: `partition${i}`,
partitionRegex,
endpoint: "an endpoint"
},
NotificationHubPartition.decode,
E.getOrElseW(e =>
fail(
`Cannot decode NotificationHubPartitions, i: ${i} error: ${readableReport(
e
)}`
)
)
)
);
Expand All @@ -45,7 +52,7 @@ describe("nhDisjoitedFirstCharacterPartitionReadonlyArray", () => {
aComplementaryPartition
]);

expect(result.isRight()).toBe(true);
expect(E.isRight(result)).toBe(true);
});

it("should not accept overlapping partitions", () => {
Expand All @@ -54,7 +61,7 @@ describe("nhDisjoitedFirstCharacterPartitionReadonlyArray", () => {
anOverlappingPartition
]);

expect(result.isRight()).toBe(false);
expect(E.isRight(result)).toBe(false);
});

it("should not accept gaped partitions", () => {
Expand All @@ -63,7 +70,7 @@ describe("nhDisjoitedFirstCharacterPartitionReadonlyArray", () => {
aGapedPartition
]);

expect(result.isRight()).toBe(false);
expect(E.isRight(result)).toBe(false);
});
});

Expand All @@ -78,8 +85,12 @@ describe("RegExpFromString", () => {
`(
"should decode $title into a regex",
({ input, expected, goodExample, badExample }) => {
const result = RegExpFromString.decode(input).getOrElseL(e =>
fail(`Cannot decode ${input}, err: ${readableReport(e)}`)
const result = pipe(
input,
RegExpFromString.decode,
E.getOrElseW(e =>
fail(`Cannot decode ${input}, err: ${readableReport(e)}`)
)
);

expect(result).toEqual(expected);
Expand Down Expand Up @@ -111,12 +122,20 @@ describe("RegExpFromString", () => {
${"a string"} | ${"foo"}
${"a regex"} | ${/^foo/}
`("should decode and encode $title idempotently", ({ input }) => {
const decoded = RegExpFromString.decode(input).getOrElseL(e =>
fail(`Cannot decode RegExpFromString, error: ${readableReport(e)}`)
const decoded = pipe(
input,
RegExpFromString.decode,
E.getOrElseW(e =>
fail(`Cannot decode RegExpFromString, error: ${readableReport(e)}`)
)
);
const encoded = RegExpFromString.encode(decoded);
const decodedAgain = RegExpFromString.decode(input).getOrElseL(e =>
fail(`Cannot decode RegExpFromString, error: ${readableReport(e)}`)
const decodedAgain = pipe(
input,
RegExpFromString.decode,
E.getOrElseW(e =>
fail(`Cannot decode RegExpFromString, error: ${readableReport(e)}`)
)
);
const encodedAgain = RegExpFromString.encode(decoded);

Expand Down

0 comments on commit e183859

Please sign in to comment.