-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add operations and tests for ADI Orders API (#27)
* Add adi-orders commands and tests * Add adi-orders id events create payload * Remove redundant helpPattern
- Loading branch information
Showing
6 changed files
with
229 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* (c) Copyright Reserved EVRYTHNG Limited 2018. | ||
* All rights reserved. Use of this material is subject to license. | ||
*/ | ||
|
||
const http = require('../modules/http'); | ||
const util = require('../modules/util'); | ||
|
||
module.exports = { | ||
about: 'Work with ADI orders.', | ||
firstArg: 'adi-orders', | ||
operations: { | ||
createAdiOrder: { | ||
execute: async ([, json]) => http.post('/adis/orders', JSON.parse(json)), | ||
pattern: 'create $payload', | ||
}, | ||
readAdiOrder: { | ||
execute: async ([id]) => http.get(`/adis/orders/${id}`), | ||
pattern: '$id read', | ||
}, | ||
|
||
createAdiOrderEvent: { | ||
execute: async ([id, , , json]) => http.post(`/adis/orders/${id}/events`, JSON.parse(json)), | ||
pattern: '$id events create $payload', | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* (c) Copyright Reserved EVRYTHNG Limited 2018. | ||
* All rights reserved. Use of this material is subject to license. | ||
*/ | ||
|
||
const { ID, mockApi } = require('../util'); | ||
const cli = require('../../src/functions/cli'); | ||
|
||
describe('adi-orders', async () => { | ||
it('should make correct request for \'adi-orders create $payload\'', async () => { | ||
const payload = JSON.stringify({ | ||
ids: [ | ||
'serial1', | ||
'serial2' | ||
], | ||
purchaseOrder: '234567890', | ||
metadata: { | ||
identifierKey: 'gs1:21', | ||
customFields: { | ||
factory: '0400321' | ||
}, | ||
product: 'gs1:01:9780345418913', | ||
tags: [ | ||
'factory:0400321' | ||
], | ||
shortDomain: 'tn.gg', | ||
defaultRedirectUrl: 'https://evrythng.com?id={shortId}' | ||
}, | ||
identifiers: { | ||
internalId: 'X7JF' | ||
}, | ||
tags: [ | ||
'X7JF' | ||
] | ||
}); | ||
mockApi() | ||
.post('/adis/orders', payload) | ||
.reply(201, {}); | ||
|
||
await cli(`adi-orders create ${payload}`); | ||
}); | ||
|
||
it('should make correct request for \'adi-orders $id read\'', async () => { | ||
mockApi() | ||
.get(`/adis/orders/${ID}`) | ||
.reply(200, {}); | ||
|
||
await cli(`adi-orders ${ID} read`); | ||
}); | ||
|
||
it('should make correct request for \'adi-orders $id events create $payload\'', async () => { | ||
const payload = JSON.stringify({ | ||
metadata: { | ||
type: 'encodings', | ||
tags: ['example'] | ||
}, | ||
ids: [ | ||
'serial1', | ||
'serial2' | ||
], | ||
customFields: { | ||
internalId: 'X7JF' | ||
}, | ||
tags: ['X7JF'] | ||
}); | ||
mockApi() | ||
.post(`/adis/orders/${ID}/events`, payload) | ||
.reply(201, {}); | ||
|
||
await cli(`adi-orders ${ID} events create ${payload}`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters