-
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
Showing
23 changed files
with
124 additions
and
127 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
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,39 +1,40 @@ | ||
import { type Job } from 'bullmq'; | ||
import emailJob from '../../src/jobs/email.job'; | ||
import { type Job } from "bullmq"; | ||
import emailJob from "../../src/jobs/email.job"; | ||
|
||
describe('emailJob', () => { | ||
describe("emailJob", () => { | ||
let consoleLogSpy: jest.SpyInstance; | ||
let consoleErrorSpy: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
consoleLogSpy = jest.spyOn(console, 'log'); | ||
consoleErrorSpy = jest.spyOn(console, 'error'); | ||
consoleLogSpy = jest.spyOn(console, "log"); | ||
consoleErrorSpy = jest.spyOn(console, "error"); | ||
}); | ||
|
||
afterEach(() => { | ||
consoleLogSpy.mockRestore(); | ||
consoleErrorSpy.mockRestore(); | ||
}); | ||
|
||
it('should process email job successfully', async () => { | ||
it("should process email job successfully", async () => { | ||
const jobData = { | ||
to: '[email protected]', | ||
subject: 'Test Subject', | ||
body: 'Test Body', | ||
to: "[email protected]", | ||
subject: "Test Subject", | ||
body: "Test Body", | ||
}; | ||
|
||
const job: Partial<Job> = { | ||
id: 'jobId', | ||
id: "jobId", | ||
data: jobData, | ||
name: 'emailJob', | ||
name: "emailJob", | ||
}; | ||
|
||
await emailJob(job as Job); | ||
|
||
expect(consoleLogSpy).toHaveBeenCalledWith(`Sending email to ${jobData.to}: ${jobData.subject}`); | ||
expect(consoleLogSpy).toHaveBeenCalledWith('Body:', jobData.body); | ||
expect(consoleLogSpy).toHaveBeenCalledWith('Email sent successfully'); | ||
expect(consoleLogSpy).toHaveBeenCalledWith( | ||
`Sending email to ${jobData.to}: ${jobData.subject}` | ||
); | ||
expect(consoleLogSpy).toHaveBeenCalledWith("Body:", jobData.body); | ||
expect(consoleLogSpy).toHaveBeenCalledWith("Email sent successfully"); | ||
expect(consoleErrorSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
}); |
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,28 +1,28 @@ | ||
import { Worker } from 'bullmq' | ||
import { emailQueue } from '../../src/queues'; | ||
import connection from '../../src/queues/connection'; | ||
import { Worker } from "bullmq"; | ||
import { emailQueue } from "../../src/queues"; | ||
import connection from "../../src/queues/connection"; | ||
|
||
jest.mock('bullmq', () => ({ | ||
jest.mock("bullmq", () => ({ | ||
...jest.requireActual("bullmq"), | ||
Worker: jest.fn().mockImplementation((queueName, processingFunction, options) => { | ||
const workerMock = { | ||
on: jest.fn(), | ||
}; | ||
return workerMock; | ||
}), | ||
Worker: jest | ||
.fn() | ||
.mockImplementation((queueName, processingFunction, options) => { | ||
const workerMock = { | ||
on: jest.fn(), | ||
}; | ||
return workerMock; | ||
}), | ||
})); | ||
|
||
describe('email.worker', () => { | ||
describe("email.worker", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should create a new BullMQ worker for emailQueue', async () => { | ||
require('../../src/workers/email.worker') | ||
expect(Worker).toHaveBeenCalledWith( | ||
emailQueue.name, | ||
expect.any(Function), | ||
{ connection } | ||
); | ||
it("should create a new BullMQ worker for emailQueue", async () => { | ||
require("../../src/workers/email.worker"); | ||
expect(Worker).toHaveBeenCalledWith(emailQueue.name, expect.any(Function), { | ||
connection, | ||
}); | ||
}); | ||
}); |
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,7 +1,4 @@ | ||
import createJob from "./createJob.controller"; | ||
import getJob from "./getJob.controller"; | ||
|
||
export { | ||
createJob, | ||
getJob | ||
} | ||
export { createJob, getJob }; |
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,6 +1,6 @@ | ||
import { Queue } from "bullmq"; | ||
import connection from "./connection"; | ||
|
||
const emailQueue = new Queue('email', { connection }) | ||
const emailQueue = new Queue("email", { connection }); | ||
|
||
export default emailQueue; | ||
export default emailQueue; |
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,6 +1,6 @@ | ||
import { Queue } from "bullmq"; | ||
import connection from "./connection"; | ||
|
||
const imageProcessingQueue = new Queue('imageProcessing', { connection }) | ||
const imageProcessingQueue = new Queue("imageProcessing", { connection }); | ||
|
||
export default imageProcessingQueue; | ||
export default imageProcessingQueue; |
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,9 +1,5 @@ | ||
import emailQueue from "./email.queue"; | ||
import imageProcessingQueue from "./imageProcessing.queue" | ||
import imageProcessingQueue from "./imageProcessing.queue"; | ||
import queueByName from "./queueByName"; | ||
|
||
export { | ||
emailQueue, | ||
imageProcessingQueue, | ||
queueByName | ||
} | ||
export { emailQueue, imageProcessingQueue, queueByName }; |
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.