Skip to content

Commit

Permalink
Merge pull request #1123 from bcgov/feature/ns-to-gw-list-display-name
Browse files Browse the repository at this point in the history
return display name on /gateways
  • Loading branch information
rustyjux authored Aug 14, 2024
2 parents 6e1c3f5 + fa0220a commit 857a857
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
20 changes: 20 additions & 0 deletions e2e/cypress/tests/19-api-v3/03-gateways.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ describe('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 }) =>
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(
Expand Down
12 changes: 9 additions & 3 deletions src/controllers/v3/GatewayController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,24 @@ export class NamespaceController extends Controller {
}

/**
* @summary List of Gateway IDs
* @summary List of Gateways available to the user
* @param request
* @returns
*/
@Get()
@OperationId('gateway-list')
public async list(@Request() request: any): Promise<string[]> {
public async list(@Request() request: any): Promise<Gateway[]> {
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();
return result.data.allNamespaces
.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);
});
}

/**
Expand Down Expand Up @@ -281,6 +286,7 @@ const list = gql`
query Namespaces {
allNamespaces {
name
displayName
}
}
`;
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/v3/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 857a857

Please sign in to comment.