Skip to content

Commit 76f7db7

Browse files
authored
Merge pull request #194 from contentstack/next
updated sanity test due to changes in variants reponse
2 parents e8b1f88 + 0d48a88 commit 76f7db7

21 files changed

+435
-225
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# Changelog
2+
## [v1.18.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.1) (2024-09-27)
3+
- Fix
4+
- Variants testcases Added
5+
## [v1.18.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.0) (2024-09-12)
6+
- Feature
7+
- Variants Support Added
28
## [v1.17.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.17.2) (2024-08-28)
39
- Fix
410
- QS version bump

lib/stack/contentType/entry/variants/index.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,10 @@ export function VariantsCollection(http, data) {
148148
return new Variants(http, {
149149
content_type_uid: data.content_type_uid,
150150
entry_uid: variant.uid,
151-
variants_uid: variant.variant_id,
151+
variants_uid: variant._variant._uid,
152152
stackHeaders: data.stackHeaders,
153153
variants: variant
154154
})
155155
})
156156
return variantCollection
157157
}
158-
159-
export function createFormData(variants) {
160-
return () => {
161-
const formData = new FormData()
162-
const uploadStream = createReadStream(variants)
163-
formData.append('variants', uploadStream)
164-
return formData
165-
}
166-
}

lib/stack/variantGroup/variants/index.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import cloneDeep from 'lodash/cloneDeep'
2-
import { create, update, fetch, query } from '../../../entity'
2+
import { create, fetch, query, deleteEntity } from '../../../entity'
33

44
/**
55
* 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>.
66
* @namespace Variants
77
*/
88

9-
export function Variants (http, data = {}) {
9+
export function Variants(http, data = {}) {
10+
Object.assign(this, cloneDeep(data.variants))
1011
this.stackHeaders = data.stackHeaders
1112
this.variant_group_uid = data.variant_group_uid
1213
this.urlPath = `/variant_groups/${this.variant_group_uid}/variants`
1314

1415
if (data.variants) {
15-
Object.assign(this, cloneDeep(data.variants))
1616
this.urlPath += `/${this.uid}`
1717
/**
1818
* @description The Update Variants call lets you update the name and description of an existing Variants.
@@ -30,7 +30,7 @@ export function Variants (http, data = {}) {
3030
this.update = async (data) => {
3131
try {
3232
const response = await http.put(this.urlPath,
33-
data,
33+
data,
3434
{
3535
headers: {
3636
...cloneDeep(this.stackHeaders)
@@ -61,6 +61,20 @@ export function Variants (http, data = {}) {
6161
*
6262
*/
6363
this.fetch = fetch(http, 'variants')
64+
65+
/**
66+
* @description The Delete Variant call is used to delete an existing Variant permanently from your Stack.
67+
* @memberof VariantGroup
68+
* @func delete
69+
* @returns {Object} Response Object.
70+
* @example
71+
* import * as contentstack from '@contentstack/management'
72+
* const client = contentstack.client()
73+
*
74+
* client.stack({ api_key: 'api_key'}).VariantGroup('variant_group_uid').variants('variant_uid').delete()
75+
* .then((response) => console.log(response.notice))
76+
*/
77+
this.delete = deleteEntity(http)
6478
} else {
6579
/**
6680
* @description The Create a variant group call creates a new variant group in a particular stack of your Contentstack account.
@@ -105,10 +119,10 @@ export function Variants (http, data = {}) {
105119
return this
106120
}
107121

108-
export function VariantsCollection (http, data) {
122+
export function VariantsCollection(http, data) {
109123
const obj = cloneDeep(data.variants) || []
110124
const variantsCollection = obj.map((userdata) => {
111-
return new Variants(http, { variants: userdata, variant_group_uid: data.variant_group_uid ,stackHeaders: data.stackHeaders })
125+
return new Variants(http, { variants: userdata, variant_group_uid: data.uid, stackHeaders: data.stackHeaders })
112126
})
113127
return variantsCollection
114128
}

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/management",
3-
"version": "1.18.0",
3+
"version": "1.18.1",
44
"description": "The Content Management API is used to manage the content of your Contentstack account",
55
"main": "./dist/node/contentstack-management.js",
66
"browser": "./dist/web/contentstack-management.js",

test/api/mock/variantGroup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const createVariantGroup2 = {
5151
"created_at": "2022-10-26T06:52:20.073Z",
5252
"updated_at": "2023-09-25T04:55:56.549Z",
5353
"content_types": [
54-
"iphone_product_description"
54+
"iphone_prod_desc"
5555
],
5656
"variant_count": 1,
5757
"variants": [

test/api/organization-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Organization api test', () => {
4141
})
4242

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

5252
it('Get all stacks in an Organization', done => {
53-
organization.stacks()
53+
client.organization(organization).stacks()
5454
.then((response) => {
5555
for (const index in response.items) {
5656
const stack = response.items[index]

test/sanity-check/api/contentType-delete-test.js

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ describe('Content Type delete api Test', () => {
3131
})
3232
.catch(done)
3333
})
34+
35+
it('should delete Variant ContentTypes', done => {
36+
makeContentType('iphone_prod_desc')
37+
.delete()
38+
.then((contentType) => {
39+
expect(contentType.notice).to.be.equal('Content Type deleted successfully.')
40+
done()
41+
})
42+
.catch(done)
43+
})
3444
})
3545

3646
function makeContentType (uid = null) {

test/sanity-check/api/contentType-test.js

+20-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path'
22
import { expect } from 'chai'
33
import { describe, it, setup } from 'mocha'
44
import { jsonReader } from '../utility/fileOperations/readwrite.js'
5-
import { singlepageCT, multiPageCT, schema } from '../mock/content-type.js'
5+
import { singlepageCT, multiPageCT, multiPageVarCT, schema } from '../mock/content-type.js'
66
import { contentstackClient } from '../utility/ContentstackClient.js'
77

88
let client = {}
@@ -37,6 +37,16 @@ describe('Content Type api Test', () => {
3737
})
3838
.catch(done)
3939
})
40+
it('should create Multi page ContentType Schema for creating variants group', done => {
41+
makeContentType()
42+
.create(multiPageVarCT)
43+
.then((contentType) => {
44+
expect(contentType.uid).to.be.equal(multiPageVarCT.content_type.uid)
45+
expect(contentType.title).to.be.equal(multiPageVarCT.content_type.title)
46+
done()
47+
})
48+
.catch(done)
49+
})
4050

4151
it('should get all ContentType', done => {
4252
makeContentType()
@@ -95,15 +105,15 @@ describe('Content Type api Test', () => {
95105
.catch(done)
96106
})
97107

98-
// it('should update Multi page ContentType Schema without fetch', done => {
99-
// makeContentType(multiPageCT.content_type.uid)
100-
// .updateCT(multiPageCT)
101-
// .then((contentType) => {
102-
// expect(contentType.content_type.schema.length).to.be.equal(2)
103-
// done()
104-
// })
105-
// .catch(done)
106-
// })
108+
it('should update Multi page ContentType Schema without fetch', done => {
109+
makeContentType(multiPageCT.content_type.uid)
110+
.updateCT(multiPageCT)
111+
.then((contentType) => {
112+
expect(contentType.content_type.schema.length).to.be.equal(2)
113+
done()
114+
})
115+
.catch(done)
116+
})
107117

108118

109119
it('should import content type', done => {

test/sanity-check/api/entry-test.js

+31-24
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ describe('Entry api Test', () => {
6666
.then((entry) => {
6767
expect(entry.uid).to.be.not.equal(null)
6868
expect(entry.title).to.be.equal(entryFirst.title)
69-
expect(entry.single_line).to.be.equal(entryFirst.single_line)
7069
expect(entry.url).to.be.equal(`/${entryFirst.title.toLowerCase().replace(/ /g, '-')}`)
71-
expect(entry.multi_line).to.be.equal(entryFirst.multi_line)
72-
expect(entry.markdown).to.be.equal(entryFirst.markdown)
7370
done()
7471
})
7572
.catch(done)
@@ -82,9 +79,6 @@ describe('Entry api Test', () => {
8279
expect(entry.uid).to.be.not.equal(null)
8380
expect(entry.title).to.be.equal(entrySecond.title)
8481
expect(entry.url).to.be.equal(`/${entrySecond.title.toLowerCase().replace(/ /g, '-')}`)
85-
expect(entry.single_line).to.be.equal(entrySecond.single_line)
86-
expect(entry.multi_line).to.be.equal(entrySecond.multi_line)
87-
expect(entry.markdown).to.be.equal(entrySecond.markdown)
8882
expect(entry.tags[0]).to.be.equal(entrySecond.tags[0])
8983
done()
9084
})
@@ -98,9 +92,6 @@ describe('Entry api Test', () => {
9892
expect(entry.uid).to.be.not.equal(null)
9993
expect(entry.title).to.be.equal(entryThird.title)
10094
expect(entry.url).to.be.equal(`/${entryThird.title.toLowerCase().replace(/ /g, '-')}`)
101-
expect(entry.single_line).to.be.equal(entryThird.single_line)
102-
expect(entry.multi_line).to.be.equal(entryThird.multi_line)
103-
expect(entry.markdown).to.be.equal(entryThird.markdown)
10495
expect(entry.tags[0]).to.be.equal(entryThird.tags[0])
10596
done()
10697
})
@@ -138,10 +129,12 @@ describe('Entry api Test', () => {
138129

139130
it('should publish Entry', done => {
140131
makeEntry(singlepageCT.content_type.uid, entryUTD)
141-
.publish({ publishDetails: {
142-
locales: ['en-us'],
143-
environments: ['development']
144-
} })
132+
.publish({
133+
publishDetails: {
134+
locales: ['en-us'],
135+
environments: ['development']
136+
}
137+
})
145138
.then((data) => {
146139
expect(data.notice).to.be.equal('The requested action has been performed.')
147140
done()
@@ -151,11 +144,13 @@ describe('Entry api Test', () => {
151144

152145
it('should publish localized Entry to locales', done => {
153146
makeEntry(singlepageCT.content_type.uid, entryUTD)
154-
.publish({ publishDetails: {
155-
locales: ['hi-in', 'en-at'],
156-
environments: ['development']
157-
},
158-
locale: 'en-at' })
147+
.publish({
148+
publishDetails: {
149+
locales: ['hi-in', 'en-at'],
150+
environments: ['development']
151+
},
152+
locale: 'en-at'
153+
})
159154
.then((data) => {
160155
expect(data.notice).to.be.equal('The requested action has been performed.')
161156
done()
@@ -177,11 +172,13 @@ describe('Entry api Test', () => {
177172

178173
it('should unpublish localized entry', done => {
179174
makeEntry(singlepageCT.content_type.uid, entryUTD)
180-
.unpublish({ publishDetails: {
181-
locales: ['hi-in', 'en-at'],
182-
environments: ['development']
183-
},
184-
locale: 'en-at' })
175+
.unpublish({
176+
publishDetails: {
177+
locales: ['hi-in', 'en-at'],
178+
environments: ['development']
179+
},
180+
locale: 'en-at'
181+
})
185182
.then((data) => {
186183
expect(data.notice).to.be.equal('The requested action has been performed.')
187184
done()
@@ -201,8 +198,18 @@ describe('Entry api Test', () => {
201198
})
202199
.catch(done)
203200
})
201+
202+
it('should get entry variants of the given Entry uid', done => {
203+
makeEntry(singlepageCT.content_type.uid, entryUTD).includeVariants('true', 'variants_uid')
204+
.then((response) => {
205+
expect(response.uid).to.be.not.equal(null)
206+
expect(response._variants).to.be.not.equal(null)
207+
done()
208+
})
209+
.catch(done)
210+
})
204211
})
205212

206-
function makeEntry (contentType, uid = null) {
213+
function makeEntry(contentType, uid = null) {
207214
return client.stack({ api_key: process.env.API_KEY }).contentType(contentType).entry(uid)
208215
}

test/sanity-check/api/organization-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('Organization api test', () => {
4242
})
4343

4444
it('should fetch organization', done => {
45-
organization.fetch()
45+
client.organization(organizationUID).fetch()
4646
.then((organizations) => {
4747
expect(organizations.name).not.to.be.equal(null, 'Organization does not exist')
4848
done()
@@ -91,7 +91,7 @@ describe('Organization api test', () => {
9191
})
9292

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

0 commit comments

Comments
 (0)