Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-4548] Support optional responses #928

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions playground/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,16 @@ export async function clients() {
const mgmntClient = new ManagementClient(program.opts());
const { data: newClient } = await mgmntClient.clients.create({ name: uuid() });
console.log('Create a client: ' + newClient.name);
const { data: client } = await mgmntClient.clients.get({ id: newClient.client_id as string });
const { data: client } = await mgmntClient.clients.get({
client_id: newClient.client_id as string,
});
console.log('Get the client: ' + client.name);
const { data: updatedClient } = await mgmntClient.clients.update(
{ id: client.client_id as string },
{ client_id: client.client_id as string },
{ name: uuid() }
);
console.log('Updated the client: ' + updatedClient.name);
await mgmntClient.clients.delete({ id: newClient.client_id as string });
await mgmntClient.clients.delete({ client_id: newClient.client_id as string });
console.log('Removed the client: ' + updatedClient.name);
}

Expand Down Expand Up @@ -524,8 +526,8 @@ export async function guardian() {

const { data: smsTemplates } = await mgmntClient.guardian.getSmsFactorTemplates();

console.log(`Get SMS enrollement message: ${smsTemplates.enrollment_message}`);
console.log(`Get SMS verification message: ${smsTemplates.verification_message}`);
console.log(`Get SMS enrollement message: ${smsTemplates?.enrollment_message}`);
console.log(`Get SMS verification message: ${smsTemplates?.verification_message}`);

const { data: updateSmsTemplates } = await mgmntClient.guardian.setSmsFactorTemplates({
enrollment_message: 'This is the encrollment message ' + uuid(),
Expand Down Expand Up @@ -794,7 +796,9 @@ export async function keys() {

const { data: newClient } = await mgmntClient.clients.create({ name: uuid() });
console.log('Create a client: ' + newClient.name);
const { data: client } = await mgmntClient.clients.get({ id: newClient.client_id as string });
const { data: client } = await mgmntClient.clients.get({
client_id: newClient.client_id as string,
});

const cert = client.signing_keys![0].cert;
const { data: keys } = await mgmntClient.keys.getAll();
Expand All @@ -803,7 +807,7 @@ export async function keys() {
const { data: key } = await mgmntClient.keys.get({ kid });
console.log('Got key:', key.kid);

await mgmntClient.clients.delete({ id: newClient.client_id as string });
await mgmntClient.clients.delete({ client_id: newClient.client_id as string });
console.log('Removed the client: ' + newClient.name);
}

Expand Down
6 changes: 4 additions & 2 deletions src/management/__generated/managers/guardian-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class GuardianManager extends BaseAPI {
*/
async getSmsFactorTemplates(
initOverrides?: InitOverride
): Promise<ApiResponse<TemplateMessages>> {
): Promise<ApiResponse<TemplateMessages | void>> {
const response = await this.request(
{
path: `/guardian/factors/sms/templates`,
Expand All @@ -144,7 +144,9 @@ export class GuardianManager extends BaseAPI {
initOverrides
);

return runtime.JSONApiResponse.fromResponse(response);
return response.status === 204
? runtime.VoidApiResponse.fromResponse(response)
: runtime.JSONApiResponse.fromResponse(response);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/management/__generated/managers/jobs-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class JobsManager extends BaseAPI {
async getErrors(
requestParameters: GetErrorsRequest,
initOverrides?: InitOverride
): Promise<ApiResponse<GetErrors200Response>> {
): Promise<ApiResponse<GetErrors200Response | void>> {
runtime.validateRequiredRequestParams(requestParameters, ['id']);

const response = await this.request(
Expand All @@ -36,7 +36,9 @@ export class JobsManager extends BaseAPI {
initOverrides
);

return runtime.JSONApiResponse.fromResponse(response);
return response.status === 204
? runtime.VoidApiResponse.fromResponse(response)
: runtime.JSONApiResponse.fromResponse(response);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions test/management/guardian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ describe('GuardianManager', () => {

await expect(guardian.getSmsFactorTemplates()).resolves.toHaveProperty('data', data);
});

it('should not fail when no response returned', async () => {
nock(API_URL).get('/guardian/factors/sms/templates').reply(204);

await expect(guardian.getSmsFactorTemplates()).resolves.not.toThrow();
});
});

describe('#getFactors', () => {
Expand Down
8 changes: 8 additions & 0 deletions test/management/jobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ describe('JobsManager', () => {
done();
});
});

it('should not fail when no response returned', async () => {
nock.cleanAll();

nock(API_URL).get(`/jobs/${id}/errors`).reply(204);

await expect(jobs.getErrors({ id: id })).resolves.not.toThrow();
});
});

const usersFilePath = path.join(__dirname, '../data/users.json');
Expand Down