Skip to content

Commit 7e97085

Browse files
Added update method testcases
1 parent cfcad6d commit 7e97085

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

lib/stack/globalField/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export function GlobalField (http, data = {}) {
7575
* })
7676
*/
7777
this.updateNestedGlobalField = async (config, headers={}) => {
78-
this.stackHeaders = {api_version: '3.2' }
78+
const apiVersion = {api_version: '3.2' }
79+
this.stackHeaders = {...this.stackHeaders, ...apiVersion, ...headers}
7980
try {
8081
const headers = {
8182
headers: { ...cloneDeep(this.stackHeaders) }

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { expect } from 'chai'
33
import { cloneDeep } from 'lodash'
44
import { describe, it, setup } from 'mocha'
55
import { jsonReader } from '../utility/fileOperations/readwrite'
6-
import { createGlobalField, createNestedGlobalField } from '../mock/globalfield'
6+
import { createGlobalField, createNestedGlobalField, createNestedGlobalFieldForReference } from '../mock/globalfield'
77
import { contentstackClient } from '../utility/ContentstackClient.js'
88
import dotenv from 'dotenv'
99

1010
dotenv.config()
1111
let client = {}
1212
let createGlobalFieldUid = ''
13-
1413
describe("Global Field api Test", () => {
1514
setup(() => {
1615
const user = jsonReader("loggedinuser.json");
@@ -170,11 +169,23 @@ describe("Global Field api Test", () => {
170169
.catch(done);
171170
});
172171

172+
173+
it('should create nested global field for reference', done => {
174+
makeGlobalField({ api_version: '3.2' }).create(createNestedGlobalFieldForReference)
175+
.then(globalField => {
176+
expect(globalField.uid).to.be.equal(createNestedGlobalFieldForReference.global_field.uid);
177+
done();
178+
})
179+
.catch(err => {
180+
console.error('Error:', err.response?.data || err.message);
181+
done(err);
182+
});
183+
});
184+
173185
it('should create nested global field', done => {
174186
makeGlobalField({ api_version: '3.2' }).create(createNestedGlobalField)
175187
.then(globalField => {
176-
console.log('Response:', globalField);
177-
expect(globalField.uid).to.be.equal(payload.global_field.uid);
188+
expect(globalField.uid).to.be.equal(createNestedGlobalField.global_field.uid);
178189
done();
179190
})
180191
.catch(err => {
@@ -184,10 +195,9 @@ describe("Global Field api Test", () => {
184195
});
185196

186197
it('should fetch nested global field', done => {
187-
makeGlobalField('nested_global_field333', { api_version: '3.2' }).fetch()
198+
makeGlobalField(createNestedGlobalField.global_field.uid, { api_version: '3.2' }).fetch()
188199
.then(globalField => {
189-
console.log('Response:', globalField);
190-
expect(globalField.uid).to.be.equal('nested_global_field222');
200+
expect(globalField.uid).to.be.equal(createNestedGlobalField.global_field.uid);
191201
done();
192202
})
193203
.catch(err => {
@@ -207,10 +217,22 @@ describe("Global Field api Test", () => {
207217
})
208218

209219
it("should delete nested global field", (done) => {
210-
makeGlobalField("nested_global_field333", { api_version: '3.2' })
220+
makeGlobalField(createNestedGlobalField.global_field.uid, { api_version: '3.2' })
221+
.delete()
222+
.then((data) => {
223+
expect(data.notice).to.be.equal("Global Field deleted successfully.");
224+
done();
225+
})
226+
.catch((err) => {
227+
console.error("Error:", err.response?.data || err.message);
228+
done(err);
229+
});
230+
});
231+
232+
it("should delete nested global reference field", (done) => {
233+
makeGlobalField(createNestedGlobalFieldForReference.global_field.uid, { api_version: '3.2' })
211234
.delete()
212235
.then((data) => {
213-
console.log("Response:", data);
214236
expect(data.notice).to.be.equal("Global Field deleted successfully.");
215237
done();
216238
})

0 commit comments

Comments
 (0)