Skip to content

Commit

Permalink
Increasing test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
lpezet committed Oct 4, 2023
1 parent bbe6d7e commit 9b0dc08
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 224 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
examples
test
2 changes: 1 addition & 1 deletion src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Response from "./types/Response";
export default class ApiClient implements ApiClientInterface {
instance: AxiosInstance;

constructor(accessToken: string) {
constructor(accessToken: string | null) {
if (!accessToken) {
throw new Error("Required access token");
}
Expand Down
2 changes: 2 additions & 0 deletions src/domains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ export type { WorkoutModel } from "./models/WorkoutModel";
export type { WorkoutResponse } from "./models/WorkoutResponse";
export type { WorkoutSource } from "./models/WorkoutSource";

/*
export { DailyActivityService } from "./services/DailyActivityService";
export { HeartRateService } from "./services/HeartRateService";
export { PersonalInfoService } from "./services/PersonalInfoService";
export { SessionsService } from "./services/SessionsService";
export { TagsService } from "./services/TagsService";
export { WorkoutsService } from "./services/WorkoutsService";
*/
39 changes: 0 additions & 39 deletions src/domains/services/DailyActivityService.ts

This file was deleted.

39 changes: 0 additions & 39 deletions src/domains/services/HeartRateService.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/domains/services/PersonalInfoService.ts

This file was deleted.

39 changes: 0 additions & 39 deletions src/domains/services/SessionsService.ts

This file was deleted.

39 changes: 0 additions & 39 deletions src/domains/services/TagsService.ts

This file was deleted.

39 changes: 0 additions & 39 deletions src/domains/services/WorkoutsService.ts

This file was deleted.

42 changes: 42 additions & 0 deletions test/apiClient.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import ApiClient from "@api/apiClient";
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders } from "axios";
//jest.mock('axios');
jest.mock('axios', () => {
return {
create: jest.fn().mockReturnValue({
interceptors: {
request: { use: jest.fn(), eject: jest.fn() },
response: { use: jest.fn(), eject: jest.fn() },
},

get: jest.fn().mockReturnValue({ data: {} }),
}),
};
});
describe("apiClient", () => {
it("invalid_token", () => {
try {
new ApiClient(null);
fail();
} catch(e) {
// nop
}
});

it("valid_token", async () => {

const expected: AxiosResponse = {
data: {},
status: 200,
statusText: "OK",
headers: {} as AxiosResponseHeaders,
config: {} as AxiosRequestConfig
};

//(axios.create as jest.Mock).mockImplementation(() => );
const apiClient = new ApiClient('sometoken');
(apiClient.instance.get as jest.Mock).mockReturnValueOnce(expected);
const actual = await apiClient.fetch('/somepath', 'hello=world');
console.log(actual);
});
});
Loading

0 comments on commit 9b0dc08

Please sign in to comment.