-
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.
- Loading branch information
1 parent
eaadc78
commit 5ff18ed
Showing
12 changed files
with
154 additions
and
3 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
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
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,40 @@ | ||
import * as E from "fp-ts/Either"; | ||
import { DateMapping } from "../date"; | ||
|
||
describe("DateMapping", () => { | ||
it("should decode a correct dateMapping type properly", () => { | ||
const validData = { | ||
inputFieldName: "foo", | ||
dateString: "2023-12-19", | ||
mapper: "DATE_TO_ISO" | ||
}; | ||
const res = DateMapping.decode(validData); | ||
expect(E.isRight(res)).toBeTruthy(); | ||
}); | ||
it("should not decode an invalid dateMapping type properly", () => { | ||
const invalidData = { | ||
inputFieldName: "foo", | ||
dateString: "2023-12-19", | ||
mapper: "INVALID MAPPER" | ||
}; | ||
const res = DateMapping.decode(invalidData); | ||
expect(E.isLeft(res)).toBeTruthy(); | ||
}); | ||
it("should not decode if dateString is not a string", () => { | ||
const invalidData = { | ||
inputFieldName: "foo", | ||
dateString: 2023 - 12 - 19, | ||
mapper: "DATE_TO_ISO" | ||
}; | ||
const res = DateMapping.decode(invalidData); | ||
expect(E.isLeft(res)).toBeTruthy(); | ||
}); | ||
it("should not decode if inpuFieldName is missing", () => { | ||
const invalidData = { | ||
dateString: "2023-12-19", | ||
mapper: "DATE_TO_ISO" | ||
}; | ||
const res = DateMapping.decode(invalidData); | ||
expect(E.isLeft(res)).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
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
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
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
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,8 +1,10 @@ | ||
import { NonEmptyString } from "@pagopa/ts-commons/lib/strings"; | ||
import * as t from "io-ts"; | ||
|
||
export const SwitchCaseMapping = t.type({ | ||
cases: t.record(t.string, t.unknown), | ||
defaultValue: t.unknown | ||
defaultValue: t.unknown, | ||
inputFieldName: NonEmptyString | ||
}); | ||
|
||
export type SwitchCaseMapping = t.TypeOf<typeof SwitchCaseMapping>; |
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,56 @@ | ||
import { NonEmptyString } from "@pagopa/ts-commons/lib/strings"; | ||
import * as t from "io-ts"; | ||
|
||
const DateStringToUtcFormatMapping = t.type({ | ||
dateString: NonEmptyString, | ||
inputFieldName: NonEmptyString, | ||
mapper: t.literal("DATE_TO_UTC") | ||
}); | ||
|
||
type DateStringToUtcFormatMapping = t.TypeOf< | ||
typeof DateStringToUtcFormatMapping | ||
>; | ||
|
||
const IsoToUtcFormatMapping = t.type({ | ||
inputFieldName: NonEmptyString, | ||
isoString: NonEmptyString, | ||
mapper: t.literal("ISO_TO_UTC") | ||
}); | ||
|
||
type IsoToUtcFormatMapping = t.TypeOf<typeof IsoToUtcFormatMapping>; | ||
|
||
const DateStringToIsoFormatMapping = t.type({ | ||
dateString: NonEmptyString, | ||
inputFieldName: NonEmptyString, | ||
mapper: t.literal("DATE_TO_ISO") | ||
}); | ||
type DateStringToIsoFormatMapping = t.TypeOf< | ||
typeof DateStringToIsoFormatMapping | ||
>; | ||
|
||
const DateStringToTimestampFormatMapping = t.type({ | ||
dateString: NonEmptyString, | ||
inputFieldName: NonEmptyString, | ||
mapper: t.literal("DATE_TO_TIMESTAMP") | ||
}); | ||
type DateStringToTimestampFormatMapping = t.TypeOf< | ||
typeof DateStringToTimestampFormatMapping | ||
>; | ||
|
||
const DateStringFromTimestampFormatMapping = t.type({ | ||
inputFieldName: NonEmptyString, | ||
mapper: t.literal("DATE_FROM_TIMESTAMP"), | ||
timestamp: t.number | ||
}); | ||
|
||
type DateStringFromTimestampFormatMapping = t.TypeOf< | ||
typeof DateStringFromTimestampFormatMapping | ||
>; | ||
|
||
export const DateMapping = t.union([ | ||
DateStringToUtcFormatMapping, | ||
IsoToUtcFormatMapping, | ||
DateStringToIsoFormatMapping, | ||
DateStringToTimestampFormatMapping, | ||
DateStringFromTimestampFormatMapping | ||
]); |
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
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
Oops, something went wrong.