Skip to content

Commit

Permalink
BC-4964 Generate api client (#2811)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedwiper authored Sep 20, 2023
1 parent a687470 commit 8a42e7a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 46 deletions.
38 changes: 19 additions & 19 deletions src/serverApi/v3/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11178,9 +11178,9 @@ export const SchoolApiAxiosParamCreator = function (configuration?: Configuratio
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
schoolControllerGetMigration: async (schoolId: string, options: any = {}): Promise<RequestArgs> => {
legacySchoolControllerGetMigration: async (schoolId: string, options: any = {}): Promise<RequestArgs> => {
// verify required parameter 'schoolId' is not null or undefined
assertParamExists('schoolControllerGetMigration', 'schoolId', schoolId)
assertParamExists('legacySchoolControllerGetMigration', 'schoolId', schoolId)
const localVarPath = `/school/{schoolId}/migration`
.replace(`{${"schoolId"}}`, encodeURIComponent(String(schoolId)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
Expand Down Expand Up @@ -11216,11 +11216,11 @@ export const SchoolApiAxiosParamCreator = function (configuration?: Configuratio
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
schoolControllerSetMigration: async (schoolId: string, migrationBody: MigrationBody, options: any = {}): Promise<RequestArgs> => {
legacySchoolControllerSetMigration: async (schoolId: string, migrationBody: MigrationBody, options: any = {}): Promise<RequestArgs> => {
// verify required parameter 'schoolId' is not null or undefined
assertParamExists('schoolControllerSetMigration', 'schoolId', schoolId)
assertParamExists('legacySchoolControllerSetMigration', 'schoolId', schoolId)
// verify required parameter 'migrationBody' is not null or undefined
assertParamExists('schoolControllerSetMigration', 'migrationBody', migrationBody)
assertParamExists('legacySchoolControllerSetMigration', 'migrationBody', migrationBody)
const localVarPath = `/school/{schoolId}/migration`
.replace(`{${"schoolId"}}`, encodeURIComponent(String(schoolId)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
Expand Down Expand Up @@ -11268,8 +11268,8 @@ export const SchoolApiFp = function(configuration?: Configuration) {
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async schoolControllerGetMigration(schoolId: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<MigrationResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.schoolControllerGetMigration(schoolId, options);
async legacySchoolControllerGetMigration(schoolId: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<MigrationResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.legacySchoolControllerGetMigration(schoolId, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
Expand All @@ -11279,8 +11279,8 @@ export const SchoolApiFp = function(configuration?: Configuration) {
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async schoolControllerSetMigration(schoolId: string, migrationBody: MigrationBody, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<MigrationResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.schoolControllerSetMigration(schoolId, migrationBody, options);
async legacySchoolControllerSetMigration(schoolId: string, migrationBody: MigrationBody, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<MigrationResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.legacySchoolControllerSetMigration(schoolId, migrationBody, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
}
Expand All @@ -11299,8 +11299,8 @@ export const SchoolApiFactory = function (configuration?: Configuration, basePat
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
schoolControllerGetMigration(schoolId: string, options?: any): AxiosPromise<MigrationResponse> {
return localVarFp.schoolControllerGetMigration(schoolId, options).then((request) => request(axios, basePath));
legacySchoolControllerGetMigration(schoolId: string, options?: any): AxiosPromise<MigrationResponse> {
return localVarFp.legacySchoolControllerGetMigration(schoolId, options).then((request) => request(axios, basePath));
},
/**
*
Expand All @@ -11309,8 +11309,8 @@ export const SchoolApiFactory = function (configuration?: Configuration, basePat
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
schoolControllerSetMigration(schoolId: string, migrationBody: MigrationBody, options?: any): AxiosPromise<MigrationResponse> {
return localVarFp.schoolControllerSetMigration(schoolId, migrationBody, options).then((request) => request(axios, basePath));
legacySchoolControllerSetMigration(schoolId: string, migrationBody: MigrationBody, options?: any): AxiosPromise<MigrationResponse> {
return localVarFp.legacySchoolControllerSetMigration(schoolId, migrationBody, options).then((request) => request(axios, basePath));
},
};
};
Expand All @@ -11328,7 +11328,7 @@ export interface SchoolApiInterface {
* @throws {RequiredError}
* @memberof SchoolApiInterface
*/
schoolControllerGetMigration(schoolId: string, options?: any): AxiosPromise<MigrationResponse>;
legacySchoolControllerGetMigration(schoolId: string, options?: any): AxiosPromise<MigrationResponse>;

/**
*
Expand All @@ -11338,7 +11338,7 @@ export interface SchoolApiInterface {
* @throws {RequiredError}
* @memberof SchoolApiInterface
*/
schoolControllerSetMigration(schoolId: string, migrationBody: MigrationBody, options?: any): AxiosPromise<MigrationResponse>;
legacySchoolControllerSetMigration(schoolId: string, migrationBody: MigrationBody, options?: any): AxiosPromise<MigrationResponse>;

}

Expand All @@ -11356,8 +11356,8 @@ export class SchoolApi extends BaseAPI implements SchoolApiInterface {
* @throws {RequiredError}
* @memberof SchoolApi
*/
public schoolControllerGetMigration(schoolId: string, options?: any) {
return SchoolApiFp(this.configuration).schoolControllerGetMigration(schoolId, options).then((request) => request(this.axios, this.basePath));
public legacySchoolControllerGetMigration(schoolId: string, options?: any) {
return SchoolApiFp(this.configuration).legacySchoolControllerGetMigration(schoolId, options).then((request) => request(this.axios, this.basePath));
}

/**
Expand All @@ -11368,8 +11368,8 @@ export class SchoolApi extends BaseAPI implements SchoolApiInterface {
* @throws {RequiredError}
* @memberof SchoolApi
*/
public schoolControllerSetMigration(schoolId: string, migrationBody: MigrationBody, options?: any) {
return SchoolApiFp(this.configuration).schoolControllerSetMigration(schoolId, migrationBody, options).then((request) => request(this.axios, this.basePath));
public legacySchoolControllerSetMigration(schoolId: string, migrationBody: MigrationBody, options?: any) {
return SchoolApiFp(this.configuration).legacySchoolControllerSetMigration(schoolId, migrationBody, options).then((request) => request(this.axios, this.basePath));
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/store/schools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@ export default class SchoolsModule extends VuexModule {

try {
const oauthMigration: AxiosResponse<MigrationResponse> =
await this.schoolApi.schoolControllerGetMigration(this.getSchool.id);
await this.schoolApi.legacySchoolControllerGetMigration(
this.getSchool.id
);
this.setOauthMigration({
enableMigrationStart: oauthMigration.data.enableMigrationStart,
oauthMigrationPossible: !!oauthMigration.data.oauthMigrationPossible,
Expand Down Expand Up @@ -422,7 +424,7 @@ export default class SchoolsModule extends VuexModule {

try {
const oauthMigration: AxiosResponse<MigrationResponse> =
await this.schoolApi.schoolControllerSetMigration(
await this.schoolApi.legacySchoolControllerSetMigration(
this.school._id,
migrationFlags
);
Expand Down
59 changes: 34 additions & 25 deletions src/store/schools.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ axiosInitializer();

describe("schools module", () => {
const setupApi = () => {
const schoolControllerGetMigration = jest.fn<
const legacySchoolControllerGetMigration = jest.fn<
AxiosPromise<MigrationResponse>,
[schoolId: string, options?: any]
>();
const schoolControllerSetMigration = jest.fn<
const legacySchoolControllerSetMigration = jest.fn<
AxiosPromise<MigrationResponse>,
[schoolId: string, migrationBody: MigrationBody, options?: any]
>();

const apiMock: Partial<SchoolApiInterface> = {
schoolControllerGetMigration,
schoolControllerSetMigration,
legacySchoolControllerGetMigration,
legacySchoolControllerSetMigration,
};
jest
.spyOn(serverApi, "SchoolApiFactory")
.mockReturnValue(apiMock as SchoolApiInterface);

return { schoolControllerGetMigration, schoolControllerSetMigration };
return {
legacySchoolControllerGetMigration,
legacySchoolControllerSetMigration,
};
};

describe("actions", () => {
Expand Down Expand Up @@ -631,7 +634,7 @@ describe("schools module", () => {
});

const mockApi = {
schoolControllerGetMigration: jest.fn().mockResolvedValue({
legacySchoolControllerGetMigration: jest.fn().mockResolvedValue({
data: {
oauthMigrationPossible: date,
enableMigrationStart: true,
Expand All @@ -649,9 +652,9 @@ describe("schools module", () => {

await schoolsModule.fetchSchoolOAuthMigration();

expect(mockApi.schoolControllerGetMigration).toHaveBeenCalledWith(
mockSchool.id
);
expect(
mockApi.legacySchoolControllerGetMigration
).toHaveBeenCalledWith(mockSchool.id);
expect(schoolsModule.getOauthMigration).toEqual<OauthMigration>({
enableMigrationStart: true,
oauthMigrationPossible: true,
Expand All @@ -663,7 +666,7 @@ describe("schools module", () => {

describe("when school id is missing", () => {
it("should not set any migration flags ", async () => {
const { schoolControllerGetMigration } = setupApi();
const { legacySchoolControllerGetMigration } = setupApi();
const schoolsModule = new SchoolsModule({});
schoolsModule.setSchool({
...mockSchool,
Expand All @@ -672,7 +675,7 @@ describe("schools module", () => {

await schoolsModule.fetchSchoolOAuthMigration();

expect(schoolControllerGetMigration).toHaveBeenCalledTimes(1);
expect(legacySchoolControllerGetMigration).toHaveBeenCalledTimes(1);
expect(schoolsModule.getOauthMigration).toEqual<OauthMigration>({
enableMigrationStart: false,
oauthMigrationFinalFinish: "",
Expand All @@ -685,13 +688,15 @@ describe("schools module", () => {

describe("when api call fails", () => {
it("should set an error", async () => {
const { schoolControllerGetMigration } = setupApi();
const { legacySchoolControllerGetMigration } = setupApi();
const schoolsModule = new SchoolsModule({});
schoolsModule.setSchool({
...mockSchool,
});

schoolControllerGetMigration.mockRejectedValue(new AxiosError(""));
legacySchoolControllerGetMigration.mockRejectedValue(
new AxiosError("")
);

await schoolsModule.fetchSchoolOAuthMigration();

Expand All @@ -704,15 +709,15 @@ describe("schools module", () => {

describe("setSchoolOauthMigration is called", () => {
describe("when school id is given", () => {
it("should call schoolControllerSetMigration and return state of OauthMigration", async () => {
it("should call legacySchoolControllerSetMigration and return state of OauthMigration", async () => {
const date: string = new Date().toDateString();
const schoolsModule = new SchoolsModule({});
schoolsModule.setSchool({
...mockSchool,
});

const mockApi = {
schoolControllerSetMigration: jest.fn().mockResolvedValue({
legacySchoolControllerSetMigration: jest.fn().mockResolvedValue({
data: {
oauthMigrationPossible: date,
enableMigrationStart: true,
Expand All @@ -733,7 +738,9 @@ describe("schools module", () => {
oauthMigrationMandatory: false,
oauthMigrationFinished: false,
});
expect(mockApi.schoolControllerSetMigration).toHaveBeenCalledTimes(1);
expect(
mockApi.legacySchoolControllerSetMigration
).toHaveBeenCalledTimes(1);
expect(schoolsModule.getOauthMigration).toEqual<OauthMigration>({
enableMigrationStart: true,
oauthMigrationPossible: true,
Expand All @@ -744,15 +751,15 @@ describe("schools module", () => {
});

describe("when school id is give and oauthMigrationFinished exists", () => {
it("should call schoolControllerSetMigration and return state of OauthMigration", async () => {
it("should call legacySchoolControllerSetMigration and return state of OauthMigration", async () => {
const date: string = new Date().toDateString();
const schoolsModule = new SchoolsModule({});
schoolsModule.setSchool({
...mockSchool,
});

const mockApi = {
schoolControllerSetMigration: jest.fn().mockResolvedValue({
legacySchoolControllerSetMigration: jest.fn().mockResolvedValue({
data: {
oauthMigrationPossible: undefined,
enableMigrationStart: true,
Expand All @@ -773,7 +780,9 @@ describe("schools module", () => {
oauthMigrationMandatory: true,
oauthMigrationFinished: true,
});
expect(mockApi.schoolControllerSetMigration).toHaveBeenCalledTimes(1);
expect(
mockApi.legacySchoolControllerSetMigration
).toHaveBeenCalledTimes(1);
expect(schoolsModule.getOauthMigration).toEqual<OauthMigration>({
enableMigrationStart: true,
oauthMigrationPossible: false,
Expand All @@ -785,7 +794,7 @@ describe("schools module", () => {

describe("when school id is missing", () => {
it("should not set migration flags ", async () => {
const { schoolControllerSetMigration } = setupApi();
const { legacySchoolControllerSetMigration } = setupApi();
const schoolsModule = new SchoolsModule({});
schoolsModule.setSchool({
...mockSchool,
Expand All @@ -798,7 +807,7 @@ describe("schools module", () => {
oauthMigrationFinished: false,
});

expect(schoolControllerSetMigration).toHaveBeenCalledTimes(0);
expect(legacySchoolControllerSetMigration).toHaveBeenCalledTimes(0);
expect(schoolsModule.getOauthMigration).toEqual<OauthMigration>({
enableMigrationStart: false,
oauthMigrationFinalFinish: "",
Expand All @@ -811,13 +820,13 @@ describe("schools module", () => {

describe("when api call fails", () => {
it("should set an error from axios reponse", async () => {
const { schoolControllerSetMigration } = setupApi();
const { legacySchoolControllerSetMigration } = setupApi();
const schoolsModule = new SchoolsModule({});
schoolsModule.setSchool({
...mockSchool,
});

schoolControllerSetMigration.mockRejectedValue(
legacySchoolControllerSetMigration.mockRejectedValue(
new AxiosError("", "400")
);

Expand All @@ -836,13 +845,13 @@ describe("schools module", () => {
});

it("should set an default error when axios reponse is missing", async () => {
const { schoolControllerSetMigration } = setupApi();
const { legacySchoolControllerSetMigration } = setupApi();
const schoolsModule = new SchoolsModule({});
schoolsModule.setSchool({
...mockSchool,
});

schoolControllerSetMigration.mockRejectedValue(
legacySchoolControllerSetMigration.mockRejectedValue(
new AxiosError(
undefined,
undefined,
Expand Down

0 comments on commit 8a42e7a

Please sign in to comment.