Skip to content

Commit

Permalink
Add operations and tests for Thng commissioning and state (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
C-D-Lewis authored Sep 6, 2019
1 parent a1d697e commit 233b151
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/commands/thng.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,29 @@ module.exports = {
pattern: '$id actions $id read',
},

// Thng commissions
createThngCommissionsAction: {
execute: async ([identifier, , , , json]) => {
const payload = JSON.parse(json);
return http.post(`/thngs/${identifier}/actions/commissions`, payload);
},
pattern: '$identifier actions commissions create $payload',
helpPattern: '$identifier|$id actions commissions create $payload',
},
readThngCommissionState: {
execute: async ([identifier]) => http.get(`/thngs/${identifier}/commissionState`),
pattern: '$identifier commission-state read',
helpPattern: '$identifier|$id commission-state read',
},
createThngDecommissionsAction: {
execute: async ([identifier, , , , json]) => {
const payload = JSON.parse(json);
return http.post(`/thngs/${identifier}/actions/decommissions`, payload);
},
pattern: '$identifier actions decommissions create $payload',
helpPattern: '$identifier|$id actions decommissions create $payload',
},

// Thng redirection
createThngRedirection: {
execute: async ([id, , shortDomain, , json]) => {
Expand Down
30 changes: 30 additions & 0 deletions tests/commands/thng.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ describe('thngs', () => {
await cli(`thngs ${ID} actions ${ID} read`);
});

// Thng commissions actions
it('should make correct request for \'thngs $identifier actions commissions create $payload\'', async () => {
const identifier = 'gs1:01:43876';
const payload = JSON.stringify({});
mockApi()
.post(`/thngs/${identifier}/actions/commissions`, payload)
.reply(201);

await cli(`thngs ${identifier} actions commissions create ${payload}`);
});

it('should make correct request for \'thngs $identifier actions decommissions create $payload\'', async () => {
const identifier = 'gs1:01:43876';
const payload = JSON.stringify({});
mockApi()
.post(`/thngs/${identifier}/actions/decommissions`, payload)
.reply(201);

await cli(`thngs ${identifier} actions decommissions create ${payload}`);
});

it('should make correct request for \'thngs $identifier commission-state read\'', async () => {
const identifier = 'gs1:01:43876';
mockApi()
.get(`/thngs/${identifier}/commissionState?perPage=30`)
.reply(200);

await cli(`thngs ${identifier} commission-state read`);
});

// Thng redirection
it('should make correct request for \'thngs $id redirections $shortDomain create $payload\'',
async () => {
Expand Down

0 comments on commit 233b151

Please sign in to comment.