Skip to content

Commit

Permalink
add test for the decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Garma00 committed Jun 19, 2024
1 parent 76ed9a3 commit 9a5c94f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions utils/__tests__/notificationhubServicePartition.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as E from "fp-ts/lib/Either";
import { NonEmptyString } from "@pagopa/ts-commons/lib/strings";
import {
getNHLegacyConfig,
getNotificationHubPartitionConfig,
testShaForPartitionRegex
} from "../notificationhubServicePartition";
import { NHClientError } from "../notification";

import { envConfig } from "../../__mocks__/env-config.mock";
import { InstallationId } from "../../generated/notifications/InstallationId";
Expand All @@ -19,6 +21,20 @@ describe("NotificationHubServicepartition", () => {
});
});

describe("NHClientError", () => {
it("should decode a 404 as right", () => {
expect(
E.isRight(NHClientError.decode({ statusCode: 404, message: "foo" }))
).toBe(true);
});

it("should decode a 401 as left", () => {
expect(
E.isLeft(NHClientError.decode({ statusCode: 401, message: "foo" }))
).toBe(true);
});
});

describe("Partition Regex", () => {
it("should return true if sha is in partition 0 [0-3]", () => {
const aValidInstallationId = "03b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" as InstallationId;
Expand Down
2 changes: 1 addition & 1 deletion utils/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const validateInstallation = (
? TE.of(installation)
: TE.left(new Error("Invalid installation"));

const NHClientError = t.type({
export const NHClientError = t.type({
statusCode: t.literal(404)
});

Expand Down

0 comments on commit 9a5c94f

Please sign in to comment.