forked from thoughtworks/HeartBeat
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADM-662: [frontend] add version in header (#824)
- Loading branch information
Showing
12 changed files
with
197 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { setupServer } from 'msw/node' | ||
import { rest } from 'msw' | ||
import { MOCK_VERSION_URL, VERIFY_ERROR_MESSAGE, VERSION_RESPONSE } from '../fixtures' | ||
import { HttpStatusCode } from 'axios' | ||
import { headerClient } from '@src/clients/header/HeaderClient' | ||
|
||
const server = setupServer(rest.get(MOCK_VERSION_URL, (req, res, ctx) => res(ctx.status(HttpStatusCode.Ok)))) | ||
|
||
describe('header client', () => { | ||
beforeAll(() => server.listen()) | ||
afterEach(() => server.resetHandlers()) | ||
afterAll(() => server.close()) | ||
|
||
it('should get response when get header status 200', async () => { | ||
const excepted = '1.11' | ||
server.use( | ||
rest.get(MOCK_VERSION_URL, (req, res, ctx) => | ||
res(ctx.status(HttpStatusCode.Accepted), ctx.json(VERSION_RESPONSE)) | ||
) | ||
) | ||
|
||
await expect(headerClient.getVersion()).resolves.toEqual(excepted) | ||
}) | ||
|
||
it('should throw error when get version response status 500', () => { | ||
server.use( | ||
rest.get(MOCK_VERSION_URL, (req, res, ctx) => | ||
res( | ||
ctx.status(HttpStatusCode.InternalServerError), | ||
ctx.json({ | ||
hintInfo: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR, | ||
}) | ||
) | ||
) | ||
) | ||
|
||
expect(async () => { | ||
await headerClient.getVersion() | ||
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR) | ||
}) | ||
}) |
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { HttpClient } from '@src/clients/Httpclient' | ||
import { VersionResponseDTO } from '@src/clients/header/dto/request' | ||
|
||
export class HeaderClient extends HttpClient { | ||
response: VersionResponseDTO = { | ||
version: '', | ||
} | ||
|
||
getVersion = async () => { | ||
try { | ||
const res = await this.axiosInstance.get(`/version`) | ||
this.response = res.data | ||
} catch (e) { | ||
this.response = { | ||
version: '', | ||
} | ||
throw e | ||
} | ||
return this.response.version | ||
} | ||
} | ||
|
||
export const headerClient = new HeaderClient() |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface VersionResponseDTO { | ||
version: string | ||
} |
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