This commit is contained in:
syuilo 2023-09-02 12:48:28 +09:00
parent aa7d4b8b0e
commit 7e5325d8ea
1 changed files with 4 additions and 2 deletions

View File

@ -35,7 +35,7 @@ describe('FetchInstanceMetadataService', () => {
let fetchInstanceMetadataService: jest.Mocked<FetchInstanceMetadataService>; let fetchInstanceMetadataService: jest.Mocked<FetchInstanceMetadataService>;
let federatedInstanceService: jest.Mocked<FederatedInstanceService>; let federatedInstanceService: jest.Mocked<FederatedInstanceService>;
let httpRequestService: jest.Mocked<HttpRequestService>; let httpRequestService: jest.Mocked<HttpRequestService>;
let redisClient: jest.Mocked<Redis.Redis>; let redisClient: jest.Mocked<Redis>;
beforeAll(async () => { beforeAll(async () => {
app = await Test app = await Test
@ -64,7 +64,7 @@ describe('FetchInstanceMetadataService', () => {
fetchInstanceMetadataService = app.get<FetchInstanceMetadataService>(FetchInstanceMetadataService); fetchInstanceMetadataService = app.get<FetchInstanceMetadataService>(FetchInstanceMetadataService);
federatedInstanceService = app.get<FederatedInstanceService>(FederatedInstanceService) as jest.Mocked<FederatedInstanceService>; federatedInstanceService = app.get<FederatedInstanceService>(FederatedInstanceService) as jest.Mocked<FederatedInstanceService>;
redisClient = app.get<Redis.Redis>(DI.redis) as jest.Mocked<Redis.Redis>; redisClient = app.get<Redis>(DI.redis) as jest.Mocked<Redis>;
httpRequestService = app.get<HttpRequestService>(HttpRequestService) as jest.Mocked<HttpRequestService>; httpRequestService = app.get<HttpRequestService>(HttpRequestService) as jest.Mocked<HttpRequestService>;
}); });
@ -85,6 +85,7 @@ describe('FetchInstanceMetadataService', () => {
expect(federatedInstanceService.fetch).toHaveBeenCalledTimes(1); expect(federatedInstanceService.fetch).toHaveBeenCalledTimes(1);
expect(httpRequestService.getJson).toHaveBeenCalled(); expect(httpRequestService.getJson).toHaveBeenCalled();
}); });
test('Lock and don\'t update', async () => { test('Lock and don\'t update', async () => {
redisClient.set = mockRedis(); redisClient.set = mockRedis();
const now = Date.now(); const now = Date.now();
@ -98,6 +99,7 @@ describe('FetchInstanceMetadataService', () => {
expect(federatedInstanceService.fetch).toHaveBeenCalledTimes(1); expect(federatedInstanceService.fetch).toHaveBeenCalledTimes(1);
expect(httpRequestService.getJson).toHaveBeenCalledTimes(0); expect(httpRequestService.getJson).toHaveBeenCalledTimes(0);
}); });
test('Do nothing when lock not acquired', async () => { test('Do nothing when lock not acquired', async () => {
redisClient.set = mockRedis(); redisClient.set = mockRedis();
federatedInstanceService.fetch.mockReturnValue({ infoUpdatedAt: { getTime: () => now - 10 * 1000 * 60 * 60 * 24 } }); federatedInstanceService.fetch.mockReturnValue({ infoUpdatedAt: { getTime: () => now - 10 * 1000 * 60 * 60 * 24 } });