Skip to content

Commit

Permalink
test: fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xming13 committed Sep 19, 2020
1 parent 1130d54 commit 5f2b0a3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
6 changes: 4 additions & 2 deletions test/server/controllers/RedirectController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ describe('redirect API tests', () => {
const req = createRequestWithShortUrl('Aaa')
const res = httpMocks.createResponse()

redisMockClient.set('aaa', 'aa')
const longUrlAndDescription = { longUrl: 'aa', description: 'bbb' }
redisMockClient.set('aaa', JSON.stringify(longUrlAndDescription))
mockDbEmpty()

await container
Expand All @@ -349,7 +350,8 @@ describe('redirect API tests', () => {
const res = httpMocks.createResponse()

mockDbDown()
redisMockClient.set('aaa', 'aa')
const longUrlAndDescription = { longUrl: 'aa', description: 'bbb' }
redisMockClient.set('aaa', JSON.stringify(longUrlAndDescription))

await container
.get<RedirectController>(DependencyIds.redirectController)
Expand Down
6 changes: 6 additions & 0 deletions test/server/mocks/repositories/UrlRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export class UrlRepositoryMock implements UrlRepositoryInterface {
throw new Error('Not implemented')
}

getLongUrlAndDescription: (
shortUrl: string,
) => Promise<{ longUrl: string; description: string }> = () => {
throw new Error('Not implemented')
}

plainTextSearch: (
query: string,
order: SearchResultsSortOrder,
Expand Down
9 changes: 5 additions & 4 deletions test/server/repositories/UrlRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ describe('UrlRepository', () => {
})

it('should return from cache when cache is filled', async () => {
redisMockClient.set('a', 'aaa')
const longUrlAndDescription = { longUrl: 'aaa', description: 'bbb' }
redisMockClient.set('a', JSON.stringify(longUrlAndDescription))
await expect(repository.getLongUrl('a')).resolves.toBe('aaa')
})

Expand All @@ -332,10 +333,10 @@ describe('UrlRepository', () => {
})

it('should return from cache when cache is filled', async () => {
const json = JSON.stringify({ longUrl: 'aaa', description: 'bbb' })
redisMockClient.set('a', json)
const longUrlAndDescription = { longUrl: 'aaa', description: 'bbb' }
redisMockClient.set('a', JSON.stringify(longUrlAndDescription))
await expect(repository.getLongUrlAndDescription('a')).resolves.toEqual(
json,
longUrlAndDescription,
)
})

Expand Down
1 change: 1 addition & 0 deletions test/server/services/UrlManagementService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('UrlManagementService', () => {
create: jest.fn(),
findByShortUrl: jest.fn(),
getLongUrl: jest.fn(),
getLongUrlAndDescription: jest.fn(),
plainTextSearch: jest.fn(),
}

Expand Down

0 comments on commit 5f2b0a3

Please sign in to comment.