Skip to content

Commit

Permalink
style: add a default value to the body parameter of api.post
Browse files Browse the repository at this point in the history
Remove usage of the method with an empty body. Adapt unit tests
  • Loading branch information
GermainBergeron committed Oct 23, 2019
1 parent d8a40cb commit 4e8d65e
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/APICore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class API {

async post<T = {}>(
url: string,
body: any,
body: any = {},
args: RequestInit = {method: 'post', body: JSON.stringify(body), headers: {'Content-Type': 'application/json'}}
): Promise<T> {
return await this.request<T>(url, args);
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Clusters/Cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ export default class Cluster extends Resource {
}

synchronize(id: string) {
return this.api.post<{}>(`${Cluster.baseUrl}/${id}/synchronize`, {});
return this.api.post<{}>(`${Cluster.baseUrl}/${id}/synchronize`);
}
}
6 changes: 3 additions & 3 deletions src/resources/Clusters/Nodes/ClusterNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export default class ClusterNode extends Resource {
}

start(clusterId: string, id: string) {
return this.api.post<{}>(`${ClusterNode.getBaseUrl(clusterId)}/${id}/start`, {});
return this.api.post<{}>(`${ClusterNode.getBaseUrl(clusterId)}/${id}/start`);
}

stop(clusterId: string, id: string) {
return this.api.post<{}>(`${ClusterNode.getBaseUrl(clusterId)}/${id}/stop`, {});
return this.api.post<{}>(`${ClusterNode.getBaseUrl(clusterId)}/${id}/stop`);
}

dump(clusterId: string, id: string) {
return this.api.post<{}>(`${ClusterNode.getBaseUrl(clusterId)}/${id}/dumps`, {});
return this.api.post<{}>(`${ClusterNode.getBaseUrl(clusterId)}/${id}/dumps`);
}

upgrade(clusterId: string, id: string, data: ClusterNodeUpgradeDataModel) {
Expand Down
6 changes: 3 additions & 3 deletions src/resources/Clusters/Nodes/tests/ClusterNode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('clusterNode', () => {
clusterNode.start(clusterId, nodeId);

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(`${ClusterNode.getBaseUrl(clusterId)}/${nodeId}/start`, {});
expect(api.post).toHaveBeenCalledWith(`${ClusterNode.getBaseUrl(clusterId)}/${nodeId}/start`);
});
});

Expand All @@ -51,7 +51,7 @@ describe('clusterNode', () => {
clusterNode.stop(clusterId, nodeId);

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(`${ClusterNode.getBaseUrl(clusterId)}/${nodeId}/stop`, {});
expect(api.post).toHaveBeenCalledWith(`${ClusterNode.getBaseUrl(clusterId)}/${nodeId}/stop`);
});
});

Expand All @@ -61,7 +61,7 @@ describe('clusterNode', () => {
clusterNode.dump(clusterId, nodeId);

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(`${ClusterNode.getBaseUrl(clusterId)}/${nodeId}/dumps`, {});
expect(api.post).toHaveBeenCalledWith(`${ClusterNode.getBaseUrl(clusterId)}/${nodeId}/dumps`);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/resources/Clusters/tests/Clusters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Cluster', () => {
const clusterToSync = 'cluster-to-sync';
cluster.synchronize(clusterToSync);
expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(`${Cluster.baseUrl}/${clusterToSync}/synchronize`, {});
expect(api.post).toHaveBeenCalledWith(`${Cluster.baseUrl}/${clusterToSync}/synchronize`);
});
});
});
2 changes: 1 addition & 1 deletion src/resources/Organizations/Organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class Organization extends Resource {
}

create(options: CreateOrganizationOptions) {
return this.api.post<OrganizationModel>(this.buildPath(Organization.baseUrl, options), {});
return this.api.post<OrganizationModel>(this.buildPath(Organization.baseUrl, options));
}

delete(organizationId: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Organizations/tests/Organizations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Organization', () => {

organization.create({name});
expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(`${Organization.baseUrl}?name=${name}`, {});
expect(api.post).toHaveBeenCalledWith(`${Organization.baseUrl}?name=${name}`);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/resources/SecurityCache/SecurityCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class SecurityCache extends Ressource {
}

refreshCache() {
return this.api.post(`${SecurityCache.cacheUrl}/refresh`, {});
return this.api.post(`${SecurityCache.cacheUrl}/refresh`);
}

listProviders() {
Expand Down
2 changes: 1 addition & 1 deletion src/resources/SecurityCache/tests/SecurityCache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('securityCache', () => {
it('should make a POST call to the securityCache refreshCache url', () => {
securityCache.refreshCache();
expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(`${SecurityCache.cacheUrl}/refresh`, {});
expect(api.post).toHaveBeenCalledWith(`${SecurityCache.cacheUrl}/refresh`);
});
});

Expand Down

0 comments on commit 4e8d65e

Please sign in to comment.