-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: GhostApi - getByPage() * feat: sync ghost type with server [ISSUE: 40] * feat: call ghost api at hatchout [ISSUE:#39]
- Loading branch information
Showing
8 changed files
with
143 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import axios from 'axios'; | ||
import {instance, mock, when} from 'ts-mockito'; | ||
import {AxiosSupplier} from '@/api/axios/axios.supplier'; | ||
import {HttpClient} from '@/api/axios/http.client'; | ||
import {GhostApi} from '@/api/ghost/ghost.api'; | ||
import {Ghost} from '@/types'; | ||
|
||
describe('GhostApi', () => { | ||
const mockAdapter = new MockAdapter(axios); | ||
const mockAxiosSupplier = mock(AxiosSupplier); | ||
when(mockAxiosSupplier.get()).thenReturn(axios.create()); | ||
|
||
const httpClient = new HttpClient(instance(mockAxiosSupplier)); | ||
const ghostApi = new GhostApi(httpClient); | ||
let responseData: Ghost; | ||
const domain = 'ghosts'; | ||
describe('getByPage()', () => { | ||
const page = 1; | ||
it('should return ghosts', async () => { | ||
responseData = { | ||
name: 'Token Name1', | ||
gene: 'token ID', | ||
tokenId: 1, | ||
userAddress: 'user1', | ||
level: 1, | ||
angelPoint: 10, | ||
devilPoint: 20, | ||
createdDate: Date.now(), | ||
}; | ||
mockAdapter.onGet(`/${domain}?page=${page}`).reply(200, responseData); | ||
|
||
expect(await ghostApi.getByPage(page)).toEqual(responseData); | ||
}); | ||
}); | ||
}); |
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,14 @@ | ||
import {Service} from 'typedi'; | ||
import {HttpClient} from '@/api/axios/http.client'; | ||
import {Ghost} from '@/types'; | ||
|
||
@Service() | ||
export class GhostApi { | ||
private domain = 'ghosts'; | ||
|
||
constructor(private httpClient: HttpClient) {} | ||
|
||
public async getByPage(page: number): Promise<Ghost[]> { | ||
return await this. httpClient.call<Ghost[]>('GET', `${this.domain}?page=${page}`); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ import {Token} from 'typedi'; | |
|
||
export default { | ||
USER_MODULE: new Token(), | ||
GHOST_MODULE: new Token(), | ||
}; |
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
export interface Ghost { | ||
readonly name: string; | ||
readonly gene: string; | ||
readonly evilPoint: number; | ||
readonly angelPoint: number; | ||
readonly tokenId: number; | ||
readonly userAddress: string; | ||
readonly level: number; | ||
readonly angelPoint: number; | ||
readonly devilPoint: number; | ||
readonly createdDate: number; | ||
} |