Skip to content

Instantly share code, notes, and snippets.

@JogoShugh
Created November 8, 2017 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JogoShugh/d2f1ffdc49f4fe9df6e2b4c3f6a3598c to your computer and use it in GitHub Desktop.
Save JogoShugh/d2f1ffdc49f4fe9df6e2b4c3f6a3598c to your computer and use it in GitHub Desktop.
API Test
import {test, assetApiPost} from '../../lib/asset-api-helper';
const types = ['yaml', 'json'];
for(const type of types) {
test(`Update Description scalar Attribute on two Stories matching a where clause by Scope OIDToken (${type})`, async t => {
const setupCommand = `
AssetType: Scope
Name: Test - Update Description scalar Scope
Parent: Scope:0
BeginDate: ${new Date().toJSON()}
Workitems:
- AssetType: Story
Name: First Story
Description: First Story Description
- AssetType: Story
Name: Second Story
Description: Second Story Description
`
let res = await assetApiPost(setupCommand);
t.is(res.status, 200, "Expected 200 OK");
t.is(res.data.assetsCreated.count, 3, "Expected 3 Assets to be created");
const scopeOidToken = res.data.assetsCreated.oidTokens[0];
const firstStoryOidToken = res.data.assetsCreated.oidTokens[1];
const secondStoryOidToken = res.data.assetsCreated.oidTokens[2];
const commands = {
yaml: `
from: Story
where:
Scope: ${scopeOidToken}
set:
Description: Now I have just the same boring description
`,
json: `
{
"from": "Story",
"where": {
"Scope": "${scopeOidToken}"
},
"set": {
"Description": "Now I have just the same boring description"
}
}
`
};
const payload = commands[type];
res = await assetApiPost(payload, type);
t.is(res.status, 200, "Expected 200 OK");
t.is(res.data.assetsModified.count, 2, "Expected 2 Assets to be modified");
const query = `
from: Story
where:
Scope: ${scopeOidToken}
select:
- Name
- Description
`
const verifyExpectation = [[
{
"_oid": firstStoryOidToken,
"Name": "First Story",
"Description": "Now I have just the same boring description"
},
{
"_oid": secondStoryOidToken,
"Name": "Second Story",
"Description": "Now I have just the same boring description"
}
]];
const verfication = await assetApiPost(query);
t.deepEqual(verfication.data.queryResult.results, verifyExpectation);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment