Skip to content

Commit

Permalink
fix(applications): updating types for application package (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
manchuck authored May 25, 2023
1 parent 6c631c8 commit 2ff4e5a
Show file tree
Hide file tree
Showing 40 changed files with 1,276 additions and 346 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"semi": true,
"singleQuote": true
}
175 changes: 175 additions & 0 deletions packages/applications/__tests__/__dataSets__/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import { Client } from '@vonage/server-client';
import { ApplicationResponse } from '../../lib';

import { BASE_URL, testApplication, capabilitiesToTest } from '../common';

const applicationToCreate = JSON.parse(JSON.stringify(testApplication));

delete applicationToCreate.id;
delete applicationToCreate.keys?.publicKey;

const expectedApplication = JSON.parse(JSON.stringify(testApplication));

expectedApplication.keys = {
...testApplication.keys,
privateKey: `-----BEGIN PRIVATE KEY-----bar----END PRIVATE KEY-----`,
};

export default [
{
label: 'create simple application',
requests: [
[
`/v2/applications`,
'POST',
Client.transformers.snakeCaseObjectKeys(applicationToCreate, true),
],
],
responses: [
[
200,
{
...Client.transformers.snakeCaseObjectKeys(
{
...testApplication,
keys: expectedApplication.keys,
},
true,
),
_links: {
self: {
href: `${BASE_URL}/v2/applications/${testApplication.id}`,
},
},
} as ApplicationResponse,
],
],
clientMethod: 'createApplication',
parameters: [applicationToCreate],
generator: false,
error: false,
expected: Client.transformers.snakeCaseObjectKeys(
expectedApplication,
true,
true,
),
},
{
label: 'create application with custom key',
requests: [
[
`/v2/applications`,
'POST',
Client.transformers.snakeCaseObjectKeys(
{
...applicationToCreate,
keys: {
public_key: expectedApplication.keys.publicKey,
},
},
true,
),
],
],
responses: [
[
200,
{
...Client.transformers.snakeCaseObjectKeys(
{
...testApplication,
keys: expectedApplication.keys,
},
true,
),
_links: {
self: {
href: `${BASE_URL}/v2/applications/${testApplication.id}`,
},
},
} as ApplicationResponse,
],
],
clientMethod: 'createApplication',
parameters: [
{
...applicationToCreate,
keys: {
publicKey: expectedApplication.keys.publicKey,
},
},
],
generator: false,
error: false,
expected: Client.transformers.snakeCaseObjectKeys(
expectedApplication,
true,
true,
),
},
capabilitiesToTest.map(([name, capability]) => ({
label: `create application with ${name} capability`,
requests: [
[
`/v2/applications`,
'POST',
Client.transformers.snakeCaseObjectKeys(
{
...applicationToCreate,
capabilities: {
[name]: capability,
},
},
true,
),
],
],
responses: [
[
200,
{
...Client.transformers.snakeCaseObjectKeys(
{
...testApplication,
keys: expectedApplication.keys,
capabilities: {
[name]: capability,
},
},
true,
),
_links: {
self: {
href: `${BASE_URL}/v2/applications/${testApplication.id}`,
},
},
} as ApplicationResponse,
],
],
clientMethod: 'createApplication',
parameters: [
{
...applicationToCreate,
capabilities: {
[name]: capability,
},
},
],
generator: false,
error: false,
expected: Client.transformers.camelCaseObjectKeys(
Client.transformers.snakeCaseObjectKeys(
{
...expectedApplication,
capabilities: {
[name]: Client.transformers.snakeCaseObjectKeys(capability, true),
},
},
true,
true,
),
true,
true,
),
})),
].flat();
14 changes: 14 additions & 0 deletions packages/applications/__tests__/__dataSets__/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { testApplication } from '../common';

export default [
{
label: 'delete simple application',
requests: [[`/v2/applications/${testApplication.id}`, 'DELETE']],
responses: [[204]],
clientMethod: 'deleteApplication',
parameters: [testApplication.id],
generator: false,
error: false,
expected: undefined,
},
];
71 changes: 71 additions & 0 deletions packages/applications/__tests__/__dataSets__/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Client } from '@vonage/server-client';
import { ApplicationResponse } from '../../lib';

import { BASE_URL, testApplication, capabilitiesToTest } from '../common';

export default [
{
label: 'get simple application',
requests: [[`/v2/applications/${testApplication.id}`, 'GET']],
responses: [
[
200,
{
...Client.transformers.snakeCaseObjectKeys(testApplication, true),
_links: {
self: {
href: `${BASE_URL}/v2/applications/${testApplication.id}`,
},
},
} as ApplicationResponse,
],
],
clientMethod: 'getApplication',
parameters: [testApplication.id],
generator: false,
error: false,
expected: Client.transformers.snakeCaseObjectKeys(
testApplication,
true,
true,
),
},
capabilitiesToTest.map(([name, capability]) => ({
label: `get application with ${name} capability`,
requests: [[`/v2/applications/${testApplication.id}`, 'GET']],
responses: [
[
200,
{
...Client.transformers.snakeCaseObjectKeys(testApplication, true),
capabilities: {
[name]: Client.transformers.snakeCaseObjectKeys(capability, true),
},
_links: {
self: {
href: `${BASE_URL}/v2/applications/${testApplication.id}`,
},
},
} as ApplicationResponse,
],
],
clientMethod: 'getApplication',
parameters: [testApplication.id],
generator: false,
error: false,
expected: Client.transformers.camelCaseObjectKeys(
Client.transformers.snakeCaseObjectKeys(
{
...testApplication,
capabilities: {
[name]: Client.transformers.snakeCaseObjectKeys(capability, true),
},
},
true,
true,
),
true,
true,
),
})),
].flat();
28 changes: 28 additions & 0 deletions packages/applications/__tests__/__dataSets__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import appTests from './get';
import listTests from './list';
import createTests from './create';
import updateTests from './update';
import deleteTests from './delete';

export default [
{
label: 'Get Application',
tests: appTests,
},
{
label: 'List Applications',
tests: listTests,
},
{
label: 'Create Application',
tests: createTests,
},
{
label: 'Update Application',
tests: updateTests,
},
{
label: 'Delete Application',
tests: deleteTests,
},
];
Loading

0 comments on commit 2ff4e5a

Please sign in to comment.