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

return display name on /gateways #1123

Merged
merged 5 commits into from
Aug 14, 2024
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
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
Loading