mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
use 403 status for non-successful mock
This commit is contained in:
@@ -42,6 +42,26 @@ async function waitForMilliseconds(ms: number): Promise<void> {
|
||||
await new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
function mockHttp2Connect(status: number) {
|
||||
class MockClient extends EventEmitter {
|
||||
request = jest.fn((headers: any) => {
|
||||
const mockRequest: any = new EventEmitter();
|
||||
mockRequest.setEncoding = jest.fn();
|
||||
mockRequest.write = jest.fn();
|
||||
mockRequest.end = jest.fn(() => {
|
||||
setTimeout(() => {
|
||||
mockRequest.emit('response', { ':status': status });
|
||||
}, 10);
|
||||
});
|
||||
return mockRequest;
|
||||
});
|
||||
|
||||
close() {};
|
||||
}
|
||||
|
||||
(http2.connect as jest.Mock) = jest.fn(() => new MockClient());
|
||||
}
|
||||
|
||||
describe("NotificationService", () => {
|
||||
let repository: UnoptimizedInMemoryRepository
|
||||
let notificationService: NotificationService;
|
||||
@@ -63,23 +83,7 @@ describe("NotificationService", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
class MockClient extends EventEmitter {
|
||||
request = jest.fn((headers: any) => {
|
||||
const mockRequest: any = new EventEmitter();
|
||||
mockRequest.setEncoding = jest.fn();
|
||||
mockRequest.write = jest.fn();
|
||||
mockRequest.end = jest.fn(() => {
|
||||
setTimeout(() => {
|
||||
mockRequest.emit('response', { ':status': 200 });
|
||||
}, 10);
|
||||
});
|
||||
return mockRequest;
|
||||
});
|
||||
|
||||
close() {};
|
||||
}
|
||||
|
||||
(http2.connect as jest.Mock) = jest.fn(() => new MockClient());
|
||||
mockHttp2Connect(200);
|
||||
});
|
||||
|
||||
describe("reloadAPNsTokenIfTimePassed", () => {
|
||||
@@ -178,6 +182,7 @@ describe("NotificationService", () => {
|
||||
const shuttle = await addMockShuttleToRepository(repository, "1");
|
||||
const stop = await addMockStopToRepository(repository, "1");
|
||||
const { eta, notificationData1 } = generateNotificationDataAndEta(shuttle, stop)
|
||||
mockHttp2Connect(403);
|
||||
|
||||
// Act
|
||||
await notificationService.scheduleNotification(notificationData1);
|
||||
|
||||
Reference in New Issue
Block a user