-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from contentstack/fix/variants-sanity
added variants to sanity check
- Loading branch information
Showing
6 changed files
with
490 additions
and
0 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,107 @@ | ||
import { expect } from 'chai' | ||
import { describe, it, setup } from 'mocha' | ||
import { jsonReader } from '../utility/fileOperations/readwrite' | ||
import { contentstackClient } from '../utility/ContentstackClient.js' | ||
|
||
var client = {} | ||
var stack = {} | ||
|
||
const variants ={ | ||
"uid": "iphone_color_white", // optional | ||
"name": "White", | ||
"personalize_metadata": { | ||
"experience_uid": "exp1", | ||
"experience_short_uid": "expShortUid1", | ||
"project_uid": "project_uid1", | ||
"variant_short_uid": "variantShort_uid1" | ||
}, | ||
} | ||
|
||
var variantsUID = '' | ||
var deleteVariantsUID = '' | ||
describe('Variants api Test', () => { | ||
setup(() => { | ||
const user = jsonReader('loggedinuser.json') | ||
stack = jsonReader('stack.json') | ||
client = contentstackClient(user.authtoken) | ||
}) | ||
|
||
it('Variants create', done => { | ||
makeVariants() | ||
.create({ variants }) | ||
.then((variantsResponse) => { | ||
variantsUID = variantsResponse.uid | ||
expect(variantsResponse.uid).to.be.not.equal(null) | ||
expect(variantsResponse.name).to.be.equal(variants.name) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Fetch variants from uid', done => { | ||
makeVariants(variantsUID) | ||
.fetch() | ||
.then((variantsResponse) => { | ||
expect(variantsResponse.uid).to.be.equal(variantsUID) | ||
expect(variantsResponse.name).to.be.equal(variants.name) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Query to get all variantss', done => { | ||
makeVariants() | ||
.query({ query: { name: variants.name } }) | ||
.find() | ||
.then((response) => { | ||
response.items.forEach((variantsResponse) => { | ||
expect(variantsResponse.uid).to.be.not.equal(null) | ||
expect(variantsResponse.name).to.be.not.equal(null) | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Query variants with name', done => { | ||
makeVariants() | ||
.query({ query: { name: variants.name } }) | ||
.find() | ||
.then((response) => { | ||
response.items.forEach((variantsResponse) => { | ||
expect(variantsResponse.uid).to.be.equal(variantsUID) | ||
expect(variantsResponse.name).to.be.equal(variants.name) | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Fetch By variants UIDs ', done => { | ||
makeVariants() | ||
.fetchByUIDs(['uid1', 'uid2']) | ||
.then((response) => { | ||
response.variants.forEach((variantsResponse) => { | ||
expect(variantsResponse.uid).to.be.equal(variantsUID) | ||
expect(variantsResponse.name).to.be.equal(variants.name) | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
|
||
it('Delete variants from uid', done => { | ||
makeVariants(deleteVariantsUID) | ||
.delete() | ||
.then((data) => { | ||
expect(data.notice).to.be.equal('Variants deleted successfully.') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
function makeVariants (uid = null) { | ||
return client.stack({ api_key: stack.api_key }).variants(uid) | ||
} |
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,136 @@ | ||
import { expect } from 'chai' | ||
import { describe, it, setup } from 'mocha' | ||
import { jsonReader } from '../utility/fileOperations/readwrite' | ||
import { createVariantGroup, createVariantGroup1, createVariantGroup2 } from '../mock/variantGroup.js' | ||
import { contentstackClient } from '../utility/ContentstackClient.js' | ||
|
||
var client = {} | ||
|
||
var stack = {} | ||
var tokenUID = '' | ||
describe('Variant Group api Test', () => { | ||
setup(() => { | ||
const user = jsonReader('loggedinuser.json') | ||
stack = jsonReader('stack.json') | ||
client = contentstackClient(user.authtoken) | ||
}) | ||
|
||
it('Add a Variant Group', done => { | ||
makeVariantGroup() | ||
.create(createVariantGroup) | ||
.then((variantGroup) => { | ||
expect(variantGroup.name).to.be.equal(createVariantGroup.name) | ||
expect(variantGroup.description).to.be.equal(createVariantGroup.description) | ||
expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup.scope[0].module) | ||
expect(variantGroup.uid).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Add a Variant Group for production', done => { | ||
makeVariantGroup() | ||
.create(createVariantGroup2) | ||
.then((variantGroup) => { | ||
tokenUID = variantGroup.uid | ||
expect(variantGroup.name).to.be.equal(createVariantGroup2.name) | ||
expect(variantGroup.description).to.be.equal(createVariantGroup2.description) | ||
expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup2.scope[0].module) | ||
expect(variantGroup.uid).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Get a Variant Group from uid', done => { | ||
makeVariantGroup(tokenUID) | ||
.fetch() | ||
.then((variantGroup) => { | ||
expect(variantGroup.name).to.be.equal(createVariantGroup1.name) | ||
expect(variantGroup.description).to.be.equal(createVariantGroup1.description) | ||
expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup1.scope[0].module) | ||
expect(variantGroup.uid).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Query to get all Variant Group', done => { | ||
makeVariantGroup() | ||
.query() | ||
.find() | ||
.then((tokens) => { | ||
tokens.items.forEach((variantGroup) => { | ||
expect(variantGroup.name).to.be.not.equal(null) | ||
expect(variantGroup.description).to.be.not.equal(null) | ||
expect(variantGroup.scope[0].module).to.be.not.equal(null) | ||
expect(variantGroup.uid).to.be.not.equal(null) | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Query to get a Variant Group from name', done => { | ||
makeVariantGroup() | ||
.query({ query: { name: createVariantGroup.name } }) | ||
.find() | ||
.then((tokens) => { | ||
tokens.items.forEach((variantGroup) => { | ||
expect(variantGroup.name).to.be.equal(createVariantGroup.name) | ||
expect(variantGroup.description).to.be.equal(createVariantGroup.description) | ||
expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup.scope[0].module) | ||
expect(variantGroup.uid).to.be.not.equal(null) | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Fetch and update a Variant Group from uid', done => { | ||
makeVariantGroup(tokenUID) | ||
.fetch() | ||
.then((variantGroup) => { | ||
variantGroup.name = 'Update Production Name' | ||
variantGroup.description = 'Update Production description' | ||
variantGroup.scope = createVariantGroup2.scope | ||
return variantGroup.update() | ||
}) | ||
.then((variantGroup) => { | ||
expect(variantGroup.name).to.be.equal('Update Production Name') | ||
expect(variantGroup.description).to.be.equal('Update Production description') | ||
expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup2.scope[0].module) | ||
expect(variantGroup.uid).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Update a Variant Group from uid', done => { | ||
const variantGroup = makeVariantGroup(tokenUID) | ||
Object.assign(variantGroup, createVariantGroup2.variantGroup) | ||
variantGroup.update() | ||
.then((variantGroup) => { | ||
expect(variantGroup.name).to.be.equal(createVariantGroup2.name) | ||
expect(variantGroup.description).to.be.equal(createVariantGroup2.description) | ||
expect(variantGroup.scope[0].module).to.be.equal(createVariantGroup2.scope[0].module) | ||
expect(variantGroup.uid).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Delete a Variant Group from uid', done => { | ||
makeVariantGroup(tokenUID) | ||
.delete() | ||
.then((data) => { | ||
expect(data.notice).to.be.equal('Variant Group deleted successfully.') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
function makeVariantGroup (uid = null) { | ||
return client.stack({ api_key: stack.api_key }).variantGroup(uid) | ||
} |
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,112 @@ | ||
import { expect } from 'chai' | ||
import { describe, it, setup } from 'mocha' | ||
import { jsonReader } from '../utility/fileOperations/readwrite' | ||
import { variant, variant1, variant2 } from '../mock/variants.js' | ||
import { contentstackClient } from '../utility/ContentstackClient.js' | ||
|
||
var client = {} | ||
|
||
var stack = {} | ||
var tokenUID = '' | ||
describe('Variants api Test', () => { | ||
setup(() => { | ||
const user = jsonReader('loggedinuser.json') | ||
stack = jsonReader('stack.json') | ||
client = contentstackClient(user.authtoken) | ||
}) | ||
|
||
it('Add a Variants', done => { | ||
makeVariants() | ||
.create(variant) | ||
.then((variants) => { | ||
expect(variants.name).to.be.equal(variant.name) | ||
expect(variants.uid).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Add a Variants for production', done => { | ||
makeVariants() | ||
.create(variant2) | ||
.then((variants) => { | ||
tokenUID = variants.uid | ||
expect(variants.name).to.be.equal(variant2.name) | ||
expect(variants.uid).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Get a Variants from uid', done => { | ||
makeVariants(tokenUID) | ||
.fetch() | ||
.then((variants) => { | ||
expect(variants.name).to.be.equal(variant2.name) | ||
expect(variants.uid).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Query to get all Variants', done => { | ||
makeVariants() | ||
.query() | ||
.find() | ||
.then((tokens) => { | ||
tokens.items.forEach((variants) => { | ||
expect(variants.name).to.be.not.equal(null) | ||
expect(variants.uid).to.be.not.equal(null) | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Query to get a Variants from name', done => { | ||
makeVariants() | ||
.query({ query: { name: variant.name } }) | ||
.find() | ||
.then((tokens) => { | ||
tokens.items.forEach((variants) => { | ||
expect(variants.name).to.be.equal(variant.name) | ||
expect(variants.uid).to.be.not.equal(null) | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Fetch and update a Variants from uid', done => { | ||
makeVariants(tokenUID) | ||
.fetch() | ||
.then((variants) => { | ||
variants.name = 'Update Production Name' | ||
variants.description = 'Update Production description' | ||
variants.scope = variant2.scope | ||
return variants.update() | ||
}) | ||
.then((variants) => { | ||
expect(variants.name).to.be.equal('Update Production Name') | ||
expect(variants.uid).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Update a Variants from uid', done => { | ||
const variants = makeVariants(tokenUID) | ||
Object.assign(variants, variant2.variants) | ||
variants.update() | ||
.then((variants) => { | ||
expect(variants.name).to.be.equal(variant2.name) | ||
expect(variants.uid).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
function makeVariants (uid = null) { | ||
return client.stack({ api_key: stack.api_key }).variantGroup('uid').variants(uid) | ||
} |
Oops, something went wrong.