From 03fb0b93acb27aa676d02f096883949274d8f45f Mon Sep 17 00:00:00 2001 From: Russell Vinegar Date: Fri, 9 Aug 2024 12:26:27 -0700 Subject: [PATCH 1/5] return display name on /gateways --- src/controllers/v3/GatewayController.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/controllers/v3/GatewayController.ts b/src/controllers/v3/GatewayController.ts index fccdece92..118bc42b3 100644 --- a/src/controllers/v3/GatewayController.ts +++ b/src/controllers/v3/GatewayController.ts @@ -105,14 +105,19 @@ export class NamespaceController extends Controller { */ @Get() @OperationId('gateway-list') - public async list(@Request() request: any): Promise { + public async list(@Request() request: any): Promise<{ gatewayId: string, displayName: string }[]> { const result = await this.keystone.executeGraphQL({ context: this.keystone.createContext(request), query: list, }); logger.debug('Result %j', result); - return result.data.allNamespaces.map((ns: Namespace) => ns.name).sort(); - } + type NamespaceInfo = { gatewayId: string, displayName: string }; + return result.data.allNamespaces + .map((ns: Namespace) => ({ gatewayId: ns.name, displayName: ns.displayName })) + .sort((a: NamespaceInfo, b: NamespaceInfo) => { + const displayNameComparison = a.displayName.localeCompare(b.displayName); + return displayNameComparison !== 0 ? displayNameComparison : a.gatewayId.localeCompare(b.gatewayId); + }); } /** * Get details about the gateway, such as permissions for what the gateway is setup with. @@ -281,6 +286,7 @@ const list = gql` query Namespaces { allNamespaces { name + displayName } } `; From 764851a09e54b370eb211ba44d27f1ba9b589b7d Mon Sep 17 00:00:00 2001 From: Russell Vinegar Date: Fri, 9 Aug 2024 12:33:12 -0700 Subject: [PATCH 2/5] update summary --- src/controllers/v3/GatewayController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/v3/GatewayController.ts b/src/controllers/v3/GatewayController.ts index 118bc42b3..560640fae 100644 --- a/src/controllers/v3/GatewayController.ts +++ b/src/controllers/v3/GatewayController.ts @@ -99,7 +99,7 @@ export class NamespaceController extends Controller { } /** - * @summary List of Gateway IDs + * @summary List of Gateways available to the user * @param request * @returns */ From 542da0e32d35bd604273bbdd7f9b7a2c0ff52c8e Mon Sep 17 00:00:00 2001 From: Russell Vinegar Date: Fri, 9 Aug 2024 13:01:43 -0700 Subject: [PATCH 3/5] use Gateway type, test --- e2e/cypress/tests/19-api-v3/03-gateways.ts | 20 ++++++++++++++++++++ src/controllers/v3/GatewayController.ts | 10 +++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/e2e/cypress/tests/19-api-v3/03-gateways.ts b/e2e/cypress/tests/19-api-v3/03-gateways.ts index d31c77a98..92b327fe8 100644 --- a/e2e/cypress/tests/19-api-v3/03-gateways.ts +++ b/e2e/cypress/tests/19-api-v3/03-gateways.ts @@ -119,6 +119,26 @@ describe('Gateways', () => { ) }) + it.only('GET /gateways', () => { + const { gateway } = workingData + cy.callAPI(`ds/api/v3/gateways`, 'GET').then( + ({ apiRes: { body, status } }: any) => { + expect(status).to.be.equal(200) + cy.log(JSON.stringify(body, null, 2)) + + // Look for the specific gateway in the response body + const foundGateway = body.find( + (item: { gatewayId: string, displayName: string }) => + item.gatewayId === gateway.gatewayId && item.displayName === gateway.displayName + ); + + // Assert that the gateway was found + expect(foundGateway).to.not.be.undefined; + cy.log(`Found gateway: ${JSON.stringify(foundGateway, null, 2)}`); + } + ) + }) + it('GET /gateways/{gatewayId}', () => { const { gateway } = workingData cy.callAPI(`ds/api/v3/gateways/${gateway.gatewayId}`, 'GET').then( diff --git a/src/controllers/v3/GatewayController.ts b/src/controllers/v3/GatewayController.ts index 560640fae..20e208481 100644 --- a/src/controllers/v3/GatewayController.ts +++ b/src/controllers/v3/GatewayController.ts @@ -105,19 +105,19 @@ export class NamespaceController extends Controller { */ @Get() @OperationId('gateway-list') - public async list(@Request() request: any): Promise<{ gatewayId: string, displayName: string }[]> { + public async list(@Request() request: any): Promise { const result = await this.keystone.executeGraphQL({ context: this.keystone.createContext(request), query: list, }); logger.debug('Result %j', result); - type NamespaceInfo = { gatewayId: string, displayName: string }; return result.data.allNamespaces - .map((ns: Namespace) => ({ gatewayId: ns.name, displayName: ns.displayName })) - .sort((a: NamespaceInfo, b: NamespaceInfo) => { + .map((ns: Namespace): Gateway => ({ gatewayId: ns.name, displayName: ns.displayName })) + .sort((a: Gateway, b: Gateway) => { const displayNameComparison = a.displayName.localeCompare(b.displayName); return displayNameComparison !== 0 ? displayNameComparison : a.gatewayId.localeCompare(b.gatewayId); - }); } + }); + } /** * Get details about the gateway, such as permissions for what the gateway is setup with. From 7e9e505cc9469584cb4314cf254f0cd8340355e4 Mon Sep 17 00:00:00 2001 From: Russell Vinegar Date: Fri, 9 Aug 2024 13:40:56 -0700 Subject: [PATCH 4/5] remove it.only --- e2e/cypress/tests/19-api-v3/03-gateways.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/cypress/tests/19-api-v3/03-gateways.ts b/e2e/cypress/tests/19-api-v3/03-gateways.ts index 92b327fe8..167c8d0d1 100644 --- a/e2e/cypress/tests/19-api-v3/03-gateways.ts +++ b/e2e/cypress/tests/19-api-v3/03-gateways.ts @@ -119,13 +119,13 @@ describe('Gateways', () => { ) }) - it.only('GET /gateways', () => { + it('GET /gateways', () => { const { gateway } = workingData cy.callAPI(`ds/api/v3/gateways`, 'GET').then( ({ apiRes: { body, status } }: any) => { expect(status).to.be.equal(200) cy.log(JSON.stringify(body, null, 2)) - + // Look for the specific gateway in the response body const foundGateway = body.find( (item: { gatewayId: string, displayName: string }) => From fa0220a4869b2ff4b4d3b5d2c4e6680df86702ab Mon Sep 17 00:00:00 2001 From: Russell Vinegar Date: Fri, 9 Aug 2024 13:44:00 -0700 Subject: [PATCH 5/5] Update openapi.yaml --- src/controllers/v3/openapi.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/v3/openapi.yaml b/src/controllers/v3/openapi.yaml index cd84dd256..2953c2a5f 100644 --- a/src/controllers/v3/openapi.yaml +++ b/src/controllers/v3/openapi.yaml @@ -891,9 +891,9 @@ paths: application/json: schema: items: - type: string + $ref: '#/components/schemas/Gateway' type: array - summary: 'List of Gateway IDs' + summary: 'List of Gateways available to the user' tags: - Gateways security: