|
| 1 | +import { LetterRepository } from "../../../../../internal/datastore/src/letter-repository"; |
| 2 | +import { LetterStatusType } from "../../../../../internal/datastore/src/types"; |
| 3 | +import { createLetter, createLetterDto } from "../../helpers/create_letter_helpers"; |
| 4 | +import { uploadFile } from "../../helpers/s3_helpers"; |
| 5 | + |
| 6 | +jest.mock("../../helpers/s3_helpers"); |
| 7 | + |
| 8 | +describe("Create letter helpers", () => { |
| 9 | + beforeEach(() => { |
| 10 | + jest.resetAllMocks(); |
| 11 | + }); |
| 12 | + |
| 13 | + it("create letter", async () => { |
| 14 | + jest.useFakeTimers(); |
| 15 | + jest.setSystemTime(new Date(2020, 1, 1)); |
| 16 | + |
| 17 | + const mockPutLetter = jest.fn(); |
| 18 | + const mockedLetterRepository = { |
| 19 | + putLetter: mockPutLetter, |
| 20 | + } as any as LetterRepository; |
| 21 | + const mockedUploadFile = uploadFile as jest.Mock; |
| 22 | + |
| 23 | + const supplierId = "supplierId"; |
| 24 | + const letterId = "letterId"; |
| 25 | + const bucketName = "bucketName"; |
| 26 | + const targetFilename = "targetFilename"; |
| 27 | + const groupId = "groupId"; |
| 28 | + const specificationId = "specificationId"; |
| 29 | + const status = "PENDING" as LetterStatusType; |
| 30 | + |
| 31 | + await createLetter({ |
| 32 | + letterId, |
| 33 | + bucketName, |
| 34 | + supplierId, |
| 35 | + targetFilename, |
| 36 | + groupId, |
| 37 | + specificationId, |
| 38 | + status, |
| 39 | + letterRepository: mockedLetterRepository, |
| 40 | + }); |
| 41 | + |
| 42 | + expect(mockedUploadFile).toHaveBeenCalledWith( |
| 43 | + "bucketName", |
| 44 | + "supplierId", |
| 45 | + "../../test_letter.pdf", |
| 46 | + "targetFilename", |
| 47 | + ); |
| 48 | + expect(mockPutLetter).toHaveBeenCalledWith({ |
| 49 | + createdAt: "2020-02-01T00:00:00.000Z", |
| 50 | + groupId: "groupId", |
| 51 | + id: "letterId", |
| 52 | + specificationId: "specificationId", |
| 53 | + status: "PENDING", |
| 54 | + supplierId: "supplierId", |
| 55 | + updatedAt: "2020-02-01T00:00:00.000Z", |
| 56 | + url: "s3://bucketName/supplierId/targetFilename", |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should create a letter DTO with correct fields", () => { |
| 61 | + jest.useFakeTimers(); |
| 62 | + jest.setSystemTime(new Date(2020, 1, 1)); |
| 63 | + |
| 64 | + const params = { |
| 65 | + letterId: "testLetterId", |
| 66 | + supplierId: "testSupplierId", |
| 67 | + specificationId: "testSpecId", |
| 68 | + groupId: "testGroupId", |
| 69 | + status: "PENDING" as LetterStatusType, |
| 70 | + url: "s3://bucket/testSupplierId/testLetter.pdf", |
| 71 | + }; |
| 72 | + |
| 73 | + const result = createLetterDto(params); |
| 74 | + |
| 75 | + expect(result).toEqual({ |
| 76 | + id: "testLetterId", |
| 77 | + supplierId: "testSupplierId", |
| 78 | + specificationId: "testSpecId", |
| 79 | + groupId: "testGroupId", |
| 80 | + url: "s3://bucket/testSupplierId/testLetter.pdf", |
| 81 | + status: "PENDING", |
| 82 | + createdAt: "2020-02-01T00:00:00.000Z", |
| 83 | + updatedAt: "2020-02-01T00:00:00.000Z", |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
0 commit comments