Created
January 9, 2019 05:36
-
-
Save JogoShugh/45e98b3835eb9ce20863fcffa3f01ec7 to your computer and use it in GitHub Desktop.
VersionOne Bulk API automated test examples
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
import {test, assetApiPost} from '../../lib/asset-api-helper'; | |
const types = ['yaml', 'json']; | |
for(const type of types) { | |
test(`Update Description LongText scalar Attribute on two Defects, replacing one exact match string with another by OIDToken (${type})`, async t => { | |
const setupCommand = ` | |
AssetType: Scope | |
Name: Test - Update Description LongText scalar Attribute on two Defects with find and replace Scope | |
Parent: Scope:0 | |
BeginDate: ${new Date().toJSON()} | |
Workitems: | |
- AssetType: Defect | |
Name: Defect 1 | |
Description: The Cog is busted in spot 1. | |
- AssetType: Defect | |
Name: Defect 2 | |
Description: The Cog is also busted in spot 2. | |
` | |
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, firstDefectOidToken, secondDefectOidToken] = res.data.assetsCreated.oidTokens; | |
const commands = { | |
yaml: ` | |
from: Defect | |
where: | |
Scope: ${scopeOidToken} | |
update: | |
Description: | |
find: Cog | |
replace: Sprocket | |
`, | |
json: ` | |
{ | |
"from": "Defect", | |
"where": { | |
"Scope": "${scopeOidToken}" | |
}, | |
"update": { | |
"Description": { | |
"find": "Cog", | |
"replace": "Sprocket" | |
} | |
} | |
} | |
` | |
}; | |
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: Defect | |
where: | |
Scope: ${scopeOidToken} | |
select: | |
- Description | |
` | |
const verifyExpectation = [[ | |
{ | |
"_oid": firstDefectOidToken, | |
"Description": "The Sprocket is busted in spot 1." | |
}, | |
{ | |
"_oid": secondDefectOidToken, | |
"Description": "The Sprocket is also busted in spot 2." | |
} | |
]]; | |
const verfication = await assetApiPost(query); | |
t.deepEqual(verfication.data.queryResult.results, verifyExpectation); | |
}); | |
} |
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
import {test, assetApiPost} from '../../lib/asset-api-helper'; | |
const commands = [ | |
{ | |
type: 'yaml', | |
payload: ` | |
AssetType: Scope | |
Name: Test - Create Scope, Epic, and Story via Subs relation Scope | |
Parent: Scope:0 | |
BeginDate: ${new Date().toJSON()} | |
Workitems: | |
- AssetType: Epic | |
Name: Epic name | |
Description: Epic description | |
Subs: | |
- AssetType: Story | |
Name: My own name | |
Description: My own description | |
- AssetType: Story | |
- AssetType: Story | |
Name: Story with Children | |
Description: Story with Children that has its own Description | |
Children: | |
- AssetType: Task | |
Name: A Task | |
- AssetType: Test | |
Name: A Test | |
`}, | |
{ | |
type: 'json', | |
payload: ` | |
{ | |
"AssetType": "Scope", | |
"Name": "Test - Create Scope, Epic, and Story via Subs relation Scope", | |
"Parent": "Scope:0", | |
"BeginDate": "${new Date().toJSON()}", | |
"Workitems": [ | |
{ | |
"AssetType": "Epic", | |
"Name": "Epic name", | |
"Description": "Epic description", | |
"Subs": [ | |
{ | |
"AssetType": "Story", | |
"Name": "My own name", | |
"Description": "My own description" | |
}, | |
{ | |
"AssetType": "Story" | |
}, | |
{ | |
"AssetType": "Story", | |
"Name": "Story with Children", | |
"Description": "Story with Children that has its own Description", | |
"Children": [ | |
{ | |
"AssetType": "Task", | |
"Name": "A Task" | |
}, | |
{ | |
"AssetType": "Test", | |
"Name": "A Test" | |
} | |
] | |
} | |
] | |
} | |
] | |
}` | |
}]; | |
for(const command of commands) { | |
test(`Create Scope, Epic, and Story via Subs relation (${command.type})`, async t => { | |
let res = await assetApiPost(command.payload, command.type); | |
t.is(res.status, 200, "Expected 200 OK"); | |
t.is(res.data.assetsCreated.count, 7, "Expected 7 Assets to be created"); | |
const [scopeOidToken, epicOidToken, story1OidToken, story2OidToken, story3OidToken, taskOidToken, testOidToken] | |
= res.data.assetsCreated.oidTokens; | |
const query = ` | |
from: Story | |
where: | |
Scope: ${scopeOidToken} | |
select: | |
- Name | |
- Description | |
- from: Children | |
select: | |
- Name | |
`; | |
const verifyExpectation = [[ | |
{ | |
"_oid": `${story1OidToken}`, | |
"Name": "My own name", | |
"Description": "My own description", | |
"Children": [] | |
}, | |
{ | |
"_oid": `${story2OidToken}`, | |
"Name": "Epic name", | |
"Description": "Epic description", | |
"Children": [] | |
}, | |
{ | |
"_oid": `${story3OidToken}`, | |
"Name": "Story with Children", | |
"Description": "Story with Children that has its own Description", | |
"Children": [ | |
{ | |
"_oid": `${taskOidToken}`, | |
"Name": "A Task" | |
}, | |
{ | |
"_oid": `${testOidToken}`, | |
"Name": "A Test" | |
} | |
] | |
} | |
]]; | |
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