Skip to content

Commit

Permalink
Merge pull request #194 from contentstack/next
Browse files Browse the repository at this point in the history
updated sanity test due to changes in variants reponse
  • Loading branch information
aman19K authored Sep 26, 2024
2 parents e8b1f88 + 0d48a88 commit 76f7db7
Show file tree
Hide file tree
Showing 21 changed files with 435 additions and 225 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog
## [v1.18.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.1) (2024-09-27)
- Fix
- Variants testcases Added
## [v1.18.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.0) (2024-09-12)
- Feature
- Variants Support Added
## [v1.17.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.17.2) (2024-08-28)
- Fix
- QS version bump
Expand Down
11 changes: 1 addition & 10 deletions lib/stack/contentType/entry/variants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,10 @@ export function VariantsCollection(http, data) {
return new Variants(http, {
content_type_uid: data.content_type_uid,
entry_uid: variant.uid,
variants_uid: variant.variant_id,
variants_uid: variant._variant._uid,
stackHeaders: data.stackHeaders,
variants: variant
})
})
return variantCollection
}

export function createFormData(variants) {
return () => {
const formData = new FormData()
const uploadStream = createReadStream(variants)
formData.append('variants', uploadStream)
return formData
}
}
26 changes: 20 additions & 6 deletions lib/stack/variantGroup/variants/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import cloneDeep from 'lodash/cloneDeep'
import { create, update, fetch, query } from '../../../entity'
import { create, fetch, query, deleteEntity } from '../../../entity'

/**
* Contentstack has a sophisticated multilingual capability. It allows you to create and publish entries in any language. This feature allows you to set up multilingual websites and cater to a wide variety of audience by serving content in their local language(s). Read more about <a href='https://www.contentstack.com/docs/developers/multi-language-content'>VariantGroups</a>.
* @namespace Variants
*/

export function Variants (http, data = {}) {
export function Variants(http, data = {}) {
Object.assign(this, cloneDeep(data.variants))
this.stackHeaders = data.stackHeaders
this.variant_group_uid = data.variant_group_uid
this.urlPath = `/variant_groups/${this.variant_group_uid}/variants`

if (data.variants) {
Object.assign(this, cloneDeep(data.variants))
this.urlPath += `/${this.uid}`
/**
* @description The Update Variants call lets you update the name and description of an existing Variants.
Expand All @@ -30,7 +30,7 @@ export function Variants (http, data = {}) {
this.update = async (data) => {
try {
const response = await http.put(this.urlPath,
data,
data,
{
headers: {
...cloneDeep(this.stackHeaders)
Expand Down Expand Up @@ -61,6 +61,20 @@ export function Variants (http, data = {}) {
*
*/
this.fetch = fetch(http, 'variants')

/**
* @description The Delete Variant call is used to delete an existing Variant permanently from your Stack.
* @memberof VariantGroup
* @func delete
* @returns {Object} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).VariantGroup('variant_group_uid').variants('variant_uid').delete()
* .then((response) => console.log(response.notice))
*/
this.delete = deleteEntity(http)
} else {
/**
* @description The Create a variant group call creates a new variant group in a particular stack of your Contentstack account.
Expand Down Expand Up @@ -105,10 +119,10 @@ export function Variants (http, data = {}) {
return this
}

export function VariantsCollection (http, data) {
export function VariantsCollection(http, data) {
const obj = cloneDeep(data.variants) || []
const variantsCollection = obj.map((userdata) => {
return new Variants(http, { variants: userdata, variant_group_uid: data.variant_group_uid ,stackHeaders: data.stackHeaders })
return new Variants(http, { variants: userdata, variant_group_uid: data.uid, stackHeaders: data.stackHeaders })
})
return variantsCollection
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/management",
"version": "1.18.0",
"version": "1.18.1",
"description": "The Content Management API is used to manage the content of your Contentstack account",
"main": "./dist/node/contentstack-management.js",
"browser": "./dist/web/contentstack-management.js",
Expand Down
2 changes: 1 addition & 1 deletion test/api/mock/variantGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const createVariantGroup2 = {
"created_at": "2022-10-26T06:52:20.073Z",
"updated_at": "2023-09-25T04:55:56.549Z",
"content_types": [
"iphone_product_description"
"iphone_prod_desc"
],
"variant_count": 1,
"variants": [
Expand Down
4 changes: 2 additions & 2 deletions test/api/organization-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Organization api test', () => {
})

it('Fetch organization', done => {
organization.fetch()
client.organization(organization).fetch()
.then((organizations) => {
expect(organizations.name).to.be.equal('SDK org', 'Organization name dose not match')
done()
Expand All @@ -50,7 +50,7 @@ describe('Organization api test', () => {
})

it('Get all stacks in an Organization', done => {
organization.stacks()
client.organization(organization).stacks()
.then((response) => {
for (const index in response.items) {
const stack = response.items[index]
Expand Down
10 changes: 10 additions & 0 deletions test/sanity-check/api/contentType-delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ describe('Content Type delete api Test', () => {
})
.catch(done)
})

it('should delete Variant ContentTypes', done => {
makeContentType('iphone_prod_desc')
.delete()
.then((contentType) => {
expect(contentType.notice).to.be.equal('Content Type deleted successfully.')
done()
})
.catch(done)
})
})

function makeContentType (uid = null) {
Expand Down
30 changes: 20 additions & 10 deletions test/sanity-check/api/contentType-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path'
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../utility/fileOperations/readwrite.js'
import { singlepageCT, multiPageCT, schema } from '../mock/content-type.js'
import { singlepageCT, multiPageCT, multiPageVarCT, schema } from '../mock/content-type.js'
import { contentstackClient } from '../utility/ContentstackClient.js'

let client = {}
Expand Down Expand Up @@ -37,6 +37,16 @@ describe('Content Type api Test', () => {
})
.catch(done)
})
it('should create Multi page ContentType Schema for creating variants group', done => {
makeContentType()
.create(multiPageVarCT)
.then((contentType) => {
expect(contentType.uid).to.be.equal(multiPageVarCT.content_type.uid)
expect(contentType.title).to.be.equal(multiPageVarCT.content_type.title)
done()
})
.catch(done)
})

it('should get all ContentType', done => {
makeContentType()
Expand Down Expand Up @@ -95,15 +105,15 @@ describe('Content Type api Test', () => {
.catch(done)
})

// it('should update Multi page ContentType Schema without fetch', done => {
// makeContentType(multiPageCT.content_type.uid)
// .updateCT(multiPageCT)
// .then((contentType) => {
// expect(contentType.content_type.schema.length).to.be.equal(2)
// done()
// })
// .catch(done)
// })
it('should update Multi page ContentType Schema without fetch', done => {
makeContentType(multiPageCT.content_type.uid)
.updateCT(multiPageCT)
.then((contentType) => {
expect(contentType.content_type.schema.length).to.be.equal(2)
done()
})
.catch(done)
})


it('should import content type', done => {
Expand Down
55 changes: 31 additions & 24 deletions test/sanity-check/api/entry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ describe('Entry api Test', () => {
.then((entry) => {
expect(entry.uid).to.be.not.equal(null)
expect(entry.title).to.be.equal(entryFirst.title)
expect(entry.single_line).to.be.equal(entryFirst.single_line)
expect(entry.url).to.be.equal(`/${entryFirst.title.toLowerCase().replace(/ /g, '-')}`)
expect(entry.multi_line).to.be.equal(entryFirst.multi_line)
expect(entry.markdown).to.be.equal(entryFirst.markdown)
done()
})
.catch(done)
Expand All @@ -82,9 +79,6 @@ describe('Entry api Test', () => {
expect(entry.uid).to.be.not.equal(null)
expect(entry.title).to.be.equal(entrySecond.title)
expect(entry.url).to.be.equal(`/${entrySecond.title.toLowerCase().replace(/ /g, '-')}`)
expect(entry.single_line).to.be.equal(entrySecond.single_line)
expect(entry.multi_line).to.be.equal(entrySecond.multi_line)
expect(entry.markdown).to.be.equal(entrySecond.markdown)
expect(entry.tags[0]).to.be.equal(entrySecond.tags[0])
done()
})
Expand All @@ -98,9 +92,6 @@ describe('Entry api Test', () => {
expect(entry.uid).to.be.not.equal(null)
expect(entry.title).to.be.equal(entryThird.title)
expect(entry.url).to.be.equal(`/${entryThird.title.toLowerCase().replace(/ /g, '-')}`)
expect(entry.single_line).to.be.equal(entryThird.single_line)
expect(entry.multi_line).to.be.equal(entryThird.multi_line)
expect(entry.markdown).to.be.equal(entryThird.markdown)
expect(entry.tags[0]).to.be.equal(entryThird.tags[0])
done()
})
Expand Down Expand Up @@ -138,10 +129,12 @@ describe('Entry api Test', () => {

it('should publish Entry', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD)
.publish({ publishDetails: {
locales: ['en-us'],
environments: ['development']
} })
.publish({
publishDetails: {
locales: ['en-us'],
environments: ['development']
}
})
.then((data) => {
expect(data.notice).to.be.equal('The requested action has been performed.')
done()
Expand All @@ -151,11 +144,13 @@ describe('Entry api Test', () => {

it('should publish localized Entry to locales', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD)
.publish({ publishDetails: {
locales: ['hi-in', 'en-at'],
environments: ['development']
},
locale: 'en-at' })
.publish({
publishDetails: {
locales: ['hi-in', 'en-at'],
environments: ['development']
},
locale: 'en-at'
})
.then((data) => {
expect(data.notice).to.be.equal('The requested action has been performed.')
done()
Expand All @@ -177,11 +172,13 @@ describe('Entry api Test', () => {

it('should unpublish localized entry', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD)
.unpublish({ publishDetails: {
locales: ['hi-in', 'en-at'],
environments: ['development']
},
locale: 'en-at' })
.unpublish({
publishDetails: {
locales: ['hi-in', 'en-at'],
environments: ['development']
},
locale: 'en-at'
})
.then((data) => {
expect(data.notice).to.be.equal('The requested action has been performed.')
done()
Expand All @@ -201,8 +198,18 @@ describe('Entry api Test', () => {
})
.catch(done)
})

it('should get entry variants of the given Entry uid', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD).includeVariants('true', 'variants_uid')
.then((response) => {
expect(response.uid).to.be.not.equal(null)
expect(response._variants).to.be.not.equal(null)
done()
})
.catch(done)
})
})

function makeEntry (contentType, uid = null) {
function makeEntry(contentType, uid = null) {
return client.stack({ api_key: process.env.API_KEY }).contentType(contentType).entry(uid)
}
4 changes: 2 additions & 2 deletions test/sanity-check/api/organization-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Organization api test', () => {
})

it('should fetch organization', done => {
organization.fetch()
client.organization(organizationUID).fetch()
.then((organizations) => {
expect(organizations.name).not.to.be.equal(null, 'Organization does not exist')
done()
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('Organization api test', () => {
})

it('should get all invitations in an organization', done => {
organization.getInvitations({ include_count: true })
client.organization(organizationUID).getInvitations({ include_count: true })
.then((response) => {
expect(response.count).to.not.equal(null, 'Failed Transfer Organization Ownership')
for (const i in response.items) {
Expand Down
Loading

0 comments on commit 76f7db7

Please sign in to comment.