Skip to content

Commit c16a46b

Browse files
feat(cc-api/commands): add GetZoneCommand
1 parent a0325b6 commit c16a46b

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/** @import { GetZoneCommandInput, GetZoneCommandOutput } from "./get-zone-command.types.js" */
2+
import { QueryParams } from '../../../../lib/request/query-params.js';
3+
import { get } from '../../../../lib/request/request-params-builder.js';
4+
import { CcApiSimpleCommand } from '../../lib/cc-api-command.js';
5+
import { transformZone } from './zone-transform.js';
6+
7+
/**
8+
*
9+
* @extends {CcApiSimpleCommand<GetZoneCommandInput, GetZoneCommandOutput>}
10+
* @endpoint [GET] /v4/products/zones/:XXX
11+
* @group Zone
12+
* @version 4
13+
*/
14+
export class GetZoneCommand extends CcApiSimpleCommand {
15+
/** @type {CcApiSimpleCommand<GetZoneCommandInput, GetZoneCommandOutput>['toRequestParams']} */
16+
toRequestParams(params) {
17+
/** @type {QueryParams} */
18+
let queryParms;
19+
if (params.ownerId != null) {
20+
queryParms = new QueryParams().append('ownerId', params.ownerId);
21+
}
22+
23+
return get(`/v4/products/zones/${params.zoneName}`, queryParms);
24+
}
25+
26+
/** @type {CcApiSimpleCommand<GetZoneCommandInput, GetZoneCommandOutput>['transformCommandOutput']} response */
27+
transformCommandOutput(response) {
28+
return transformZone(response);
29+
}
30+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { Zone } from './zone.types.js';
2+
3+
export type GetZoneCommandInput = {
4+
zoneName: string;
5+
ownerId?: string;
6+
};
7+
8+
export type GetZoneCommandOutput = Zone;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/** @import { Zone } from './zone.types.d.ts' */
2+
3+
/**
4+
* @param {any} payload
5+
* @returns {Zone}
6+
*/
7+
export function transformZone(payload) {
8+
return {
9+
id: payload.id,
10+
name: payload.name,
11+
country: payload.country,
12+
countryCode: payload.countryCode,
13+
city: payload.city,
14+
displayName: payload.displayName,
15+
lat: payload.lat,
16+
lon: payload.lon,
17+
outboundIPs: payload.outboundIPs?.sort() ?? [],
18+
tags: payload?.tags.sort() ?? [],
19+
};
20+
}

test/e2e/clients/cc-api/commands/zone-commands.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from 'chai';
2+
import { GetZoneCommand } from '../../../../../src/clients/cc-api/commands/zone/get-zone-command.js';
23
import { ListZoneCommand } from '../../../../../src/clients/cc-api/commands/zone/list-zone-command.js';
34
import { e2eSupport } from '../e2e-support.js';
45

@@ -38,4 +39,32 @@ describe('zone commands', function () {
3839
expect(response[0].outboundIPs).to.be.an('array');
3940
expect(response[0].tags).to.be.an('array');
4041
});
42+
43+
it('should get "par" zone by name without ownerId', async () => {
44+
const response = await support.client.send(new GetZoneCommand({ zoneName: 'par' }));
45+
46+
expect(response.id).to.be.a('string');
47+
expect(response.name).to.be.a('string');
48+
expect(response.country).to.be.a('string');
49+
expect(response.countryCode).to.be.a('string');
50+
expect(response.lat).to.be.a('number');
51+
expect(response.lon).to.be.a('number');
52+
expect(response.outboundIPs).to.be.an('array');
53+
expect(response.tags).to.be.an('array');
54+
});
55+
56+
it('should get "par" zone by name with ownerId', async () => {
57+
const response = await support.client.send(
58+
new GetZoneCommand({ zoneName: 'par', ownerId: support.organisationId }),
59+
);
60+
61+
expect(response.id).to.be.a('string');
62+
expect(response.name).to.be.a('string');
63+
expect(response.country).to.be.a('string');
64+
expect(response.countryCode).to.be.a('string');
65+
expect(response.lat).to.be.a('number');
66+
expect(response.lon).to.be.a('number');
67+
expect(response.outboundIPs).to.be.an('array');
68+
expect(response.tags).to.be.an('array');
69+
});
4170
});

0 commit comments

Comments
 (0)