diff --git a/test/sanity-check/api/ungroupedVariants-test.js b/test/sanity-check/api/ungroupedVariants-test.js new file mode 100644 index 00000000..a42ab83a --- /dev/null +++ b/test/sanity-check/api/ungroupedVariants-test.js @@ -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) +} diff --git a/test/sanity-check/api/variantGroup-test.js b/test/sanity-check/api/variantGroup-test.js new file mode 100644 index 00000000..e131049d --- /dev/null +++ b/test/sanity-check/api/variantGroup-test.js @@ -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) +} \ No newline at end of file diff --git a/test/sanity-check/api/variants-test.js b/test/sanity-check/api/variants-test.js new file mode 100644 index 00000000..1390d53f --- /dev/null +++ b/test/sanity-check/api/variants-test.js @@ -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) +} \ No newline at end of file diff --git a/test/sanity-check/mock/variantGroup.js b/test/sanity-check/mock/variantGroup.js new file mode 100644 index 00000000..805553be --- /dev/null +++ b/test/sanity-check/mock/variantGroup.js @@ -0,0 +1,82 @@ +const createVariantGroup = { + "name": "Colors", + "content_types": [ + "iphone_product_page" + ], + "uid": "iphone_color_white", + } + +const createVariantGroup1 = { + "created_by": "created_by_uid", + "updated_by": "updated_by_uid", + "created_at": "2022-10-26T06:52:20.073Z", + "updated_at": "2023-09-25T04:55:56.549Z", + "uid": "uid", + "name": "iPhone Colors", + "content_types": [ + "iphone_product_page" + ], + "source" : "Personalize" + } +const createVariantGroup2 = { + count: 2, + variant_groups: [ + { + "uid": "uid", + "name": "iPhone Colors", + "created_by": "created_by_uid", + "updated_by": "updated_by_uid", + "created_at": "2022-10-26T06:52:20.073Z", + "updated_at": "2023-09-25T04:55:56.549Z", + "content_types": [ + "iphone_product_page" + ], + "variant_count": 1, + "variants": [ + { + "created_by": "created_by_uid", + "updated_by": "updated_by_uid", + "created_at": "2022-10-26T06:52:20.073Z", + "updated_at": "2023-09-25T04:55:56.549Z", + "uid": "iphone_color_white", + "name": "White" + } + ] + }, + { + "uid": "uid", + "name": "iPhone", + "created_by": "created_by_uid", + "updated_by": "updated_by_uid", + "created_at": "2022-10-26T06:52:20.073Z", + "updated_at": "2023-09-25T04:55:56.549Z", + "content_types": [ + "iphone_product_description" + ], + "variant_count": 1, + "variants": [ + { + "created_by": "created_by_uid", + "updated_by": "updated_by_uid", + "created_at": "2022-10-26T06:52:20.073Z", + "updated_at": "2023-09-25T04:55:56.549Z", + "uid": "iphone_color_white", + "name": "White" + } + ] + } + ], + ungrouped_variants: [ + { + "created_by": "created_by_uid", + "updated_by": "updated_by_uid", + "created_at": "2022-10-26T06:52:20.073Z", + "updated_at": "2023-09-25T04:55:56.549Z", + "uid": "iphone_color_red", + "name": "Red" + } + ], + ungrouped_variant_count: 1 + } + +export { createVariantGroup, createVariantGroup1, createVariantGroup2 } diff --git a/test/sanity-check/mock/variants.js b/test/sanity-check/mock/variants.js new file mode 100644 index 00000000..9e590226 --- /dev/null +++ b/test/sanity-check/mock/variants.js @@ -0,0 +1,50 @@ +const variant = { + "uid": "iphone_color_white", // optional + "name": "White", + "personalize_metadata": { // optional sent from personalize while creating variant + "experience_uid": "exp1", + "experience_short_uid": "expShortUid1", + "project_uid": "project_uid1", + "variant_short_uid": "variantShort_uid1" + }, + } + +const variant1 = { + "created_by": "blt6cdf4e0b02b1c446", + "updated_by": "blt303b74fa96e1082a", + "created_at": "2022-10-26T06:52:20.073Z", + "updated_at": "2023-09-25T04:55:56.549Z", + "uid": "iphone_color_white", + "name": "White", + } +const variant2 = { + "uid": "variant_group_1", + "name": "Variant Group 1", + "content_types": [ + "CTSTAET123" + ], + "personalize_metadata": { + "experience_uid": "variant_group_ex_uid", + "experience_short_uid": "variant_group_short_uid", + "project_uid": "variant_group_project_uid" + }, + "variants": [ // variants inside the group + { + "uid": "variant1", + "created_by": "user_id", + "updated_by": "user_id", + "name": "Variant 1", + "personalize_metadata": { + "experience_uid": "exp1", + "experience_short_uid": "expShortUid1", + "project_uid": "project_uid1", + "variant_short_uid": "variantShort_uid1" + }, + "created_at": "2024-04-16T05:53:50.547Z", + "updated_at": "2024-04-16T05:53:50.547Z" + } + ], + "count": 1 +} + +export { variant, variant1, variant2 } diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index d2c047b0..f470aa13 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -21,6 +21,9 @@ require('./api/workflow-test') require('./api/globalfield-test') require('./api/release-test') require('./api/label-test') +require('./api/variants-test') +require('./api/variantGroup-test') +require('./api/ungroupedVariants-test') require('./api/contentType-delete-test') require('./api/delete-test') require('./api/team-test')