Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added variants to sanity check #184

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions test/sanity-check/api/ungroupedVariants-test.js
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)
}
136 changes: 136 additions & 0 deletions test/sanity-check/api/variantGroup-test.js
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)
}
112 changes: 112 additions & 0 deletions test/sanity-check/api/variants-test.js
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)
}
Loading
Loading