mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +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));
|
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", () => {
|
describe("NotificationService", () => {
|
||||||
let repository: UnoptimizedInMemoryRepository
|
let repository: UnoptimizedInMemoryRepository
|
||||||
let notificationService: NotificationService;
|
let notificationService: NotificationService;
|
||||||
@@ -63,23 +83,7 @@ describe("NotificationService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
class MockClient extends EventEmitter {
|
mockHttp2Connect(200);
|
||||||
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());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("reloadAPNsTokenIfTimePassed", () => {
|
describe("reloadAPNsTokenIfTimePassed", () => {
|
||||||
@@ -178,6 +182,7 @@ describe("NotificationService", () => {
|
|||||||
const shuttle = await addMockShuttleToRepository(repository, "1");
|
const shuttle = await addMockShuttleToRepository(repository, "1");
|
||||||
const stop = await addMockStopToRepository(repository, "1");
|
const stop = await addMockStopToRepository(repository, "1");
|
||||||
const { eta, notificationData1 } = generateNotificationDataAndEta(shuttle, stop)
|
const { eta, notificationData1 } = generateNotificationDataAndEta(shuttle, stop)
|
||||||
|
mockHttp2Connect(403);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await notificationService.scheduleNotification(notificationData1);
|
await notificationService.scheduleNotification(notificationData1);
|
||||||
|
|||||||
Reference in New Issue
Block a user