-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(email): proces email test (#979)
* feat(test)proces email test * Removed console.log * linter correction * removed a ine * remove brackets * add region * Address change reqeust
- Loading branch information
Showing
10 changed files
with
247 additions
and
233 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { describe, it, expect, vi } from "vitest"; | ||
import { Context } from "aws-lambda"; | ||
import { SESClient } from "@aws-sdk/client-ses"; | ||
import { sendEmail, validateEmailTemplate, handler } from "./processEmails"; | ||
import { KafkaRecord, KafkaEvent } from "node_modules/shared-types"; | ||
|
||
describe("process emails Handler", () => { | ||
it("should return 200 with a proper email", async () => { | ||
const params = { | ||
Source: "[email protected]", | ||
Destination: { ToAddresses: ["[email protected]"] }, | ||
Message: { | ||
Subject: { Data: "Mocked Email", Charset: "UTF-8" }, | ||
Body: { Text: { Data: "This is a mocked email body.", Charset: "UTF-8" } }, | ||
}, | ||
}; | ||
const test = await sendEmail(params, "us-east-1"); | ||
expect(test.status).toStrictEqual(200); | ||
}); | ||
it("should throw an error", async () => { | ||
const params = { | ||
Source: "[email protected]", | ||
Destination: { ToAddresses: ["[email protected]"] }, | ||
Message: { | ||
Subject: { Data: "Mocked Email", Charset: "UTF-8" }, | ||
Body: { Text: { Data: "This is a mocked email body.", Charset: "UTF-8" } }, | ||
}, | ||
}; | ||
await expect(sendEmail(params, "test")).rejects.toThrowError(); | ||
}); | ||
it("should validate the email template and throw an error", async () => { | ||
const template = { | ||
to: "Person", | ||
from: "Other Guy", | ||
body: "body", | ||
}; | ||
expect(() => validateEmailTemplate(template)).toThrowError(); | ||
}); | ||
it("should make a handler", async () => { | ||
const callback = vi.fn(); | ||
const secSPY = vi.spyOn(SESClient.prototype, "send"); | ||
const mockEvent: KafkaEvent = { | ||
records: { | ||
"mock-topic": [ | ||
{ | ||
key: Buffer.from("VA").toString("base64"), | ||
value: Buffer.from( | ||
JSON.stringify({ | ||
origin: "mako", | ||
event: "new-medicaid-submission", | ||
authority: "medicaid spa", | ||
}), | ||
).toString("base64"), | ||
headers: {}, | ||
timestamp: 1732645041557, | ||
offset: "0", | ||
partition: 0, | ||
topic: "mock-topic", | ||
} as unknown as KafkaRecord, | ||
], | ||
}, | ||
eventSource: "", | ||
bootstrapServers: "", | ||
}; | ||
|
||
await handler(mockEvent, {} as Context, callback); | ||
expect(secSPY).toHaveBeenCalledTimes(2); | ||
}); | ||
it("should not be mako therefor not do an event", async () => { | ||
const callback = vi.fn(); | ||
const mockEvent: KafkaEvent = { | ||
records: { | ||
"mock-topic": [ | ||
{ | ||
key: Buffer.from("VA").toString("base64"), | ||
value: Buffer.from( | ||
JSON.stringify({ | ||
origin: "not mako", | ||
event: "new-medicaid-submission", | ||
authority: "medicaid spa", | ||
}), | ||
).toString("base64"), | ||
headers: {}, | ||
timestamp: 1732645041557, | ||
offset: "0", | ||
partition: 0, | ||
topic: "mock-topic", | ||
} as unknown as KafkaRecord, | ||
], | ||
}, | ||
eventSource: "", | ||
bootstrapServers: "", | ||
}; | ||
const secSPY = vi.spyOn(SESClient.prototype, "send"); | ||
|
||
await handler(mockEvent, {} as Context, callback); | ||
expect(secSPY).toHaveBeenCalledTimes(0); | ||
}); | ||
it("should be missing a value, so nothing sent", async () => { | ||
const callback = vi.fn(); | ||
const mockEvent: KafkaEvent = { | ||
records: { | ||
"mock-topic": [ | ||
{ | ||
key: Buffer.from("VA").toString("base64"), | ||
headers: {}, | ||
timestamp: 1732645041557, | ||
offset: "0", | ||
partition: 0, | ||
topic: "mock-topic", | ||
} as unknown as KafkaRecord, | ||
], | ||
}, | ||
eventSource: "", | ||
bootstrapServers: "", | ||
}; | ||
const secSPY = vi.spyOn(SESClient.prototype, "send"); | ||
|
||
await handler(mockEvent, {} as Context, callback); | ||
expect(secSPY).toHaveBeenCalledTimes(0); | ||
}); | ||
it("should be missing an environment variable", async () => { | ||
const callback = vi.fn(); | ||
delete process.env.osDomain; | ||
const mockEvent: KafkaEvent = { | ||
records: { | ||
"mock-topic": [ | ||
{ | ||
key: Buffer.from("VA").toString("base64"), | ||
value: Buffer.from( | ||
JSON.stringify({ | ||
origin: "mako", | ||
event: "new-medicaid-submission", | ||
authority: "medicaid spa", | ||
}), | ||
).toString("base64"), | ||
headers: {}, | ||
timestamp: 1732645041557, | ||
offset: "0", | ||
partition: 0, | ||
topic: "mock-topic", | ||
} as unknown as KafkaRecord, | ||
], | ||
}, | ||
eventSource: "", | ||
bootstrapServers: "", | ||
}; | ||
await expect(handler(mockEvent, {} as Context, callback)).rejects.toThrowError( | ||
"Missing required environment variables: osDomain", | ||
); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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.