11import path from 'path'
22import { expect } from 'chai'
3+ import { cloneDeep } from 'lodash'
34import { describe , it , setup } from 'mocha'
45import { jsonReader } from '../utility/fileOperations/readwrite'
5- import { createGlobalField } from '../mock/globalfield'
6+ import { createGlobalField , createNestedGlobalField , createNestedGlobalFieldForReference } from '../mock/globalfield'
67import { contentstackClient } from '../utility/ContentstackClient.js'
78import dotenv from 'dotenv'
89
@@ -59,25 +60,16 @@ describe('Global Field api Test', () => {
5960 . catch ( done )
6061 } )
6162
62- it ( 'should update global Field' , ( done ) => {
63- makeGlobalField ( createGlobalField . global_field . uid )
64- . update ( createGlobalField )
63+ it ( 'should update global Field' , done => {
64+ const globalField = makeGlobalField ( createGlobalField . global_field . uid )
65+ Object . assign ( globalField , cloneDeep ( createGlobalField . global_field ) )
66+ globalField . update ( )
6567 . then ( ( updateGlobal ) => {
66- expect ( updateGlobal . uid ) . to . be . equal (
67- createGlobalField . global_field . uid
68- )
69- expect ( updateGlobal . title ) . to . be . equal (
70- createGlobalField . global_field . title
71- )
72- expect ( updateGlobal . schema [ 0 ] . uid ) . to . be . equal (
73- createGlobalField . global_field . schema [ 0 ] . uid
74- )
75- expect ( updateGlobal . schema [ 0 ] . data_type ) . to . be . equal (
76- createGlobalField . global_field . schema [ 0 ] . data_type
77- )
78- expect ( updateGlobal . schema [ 0 ] . display_name ) . to . be . equal (
79- createGlobalField . global_field . schema [ 0 ] . display_name
80- )
68+ expect ( updateGlobal . uid ) . to . be . equal ( createGlobalField . global_field . uid )
69+ expect ( updateGlobal . title ) . to . be . equal ( createGlobalField . global_field . title )
70+ expect ( updateGlobal . schema [ 0 ] . uid ) . to . be . equal ( createGlobalField . global_field . schema [ 0 ] . uid )
71+ expect ( updateGlobal . schema [ 0 ] . data_type ) . to . be . equal ( createGlobalField . global_field . schema [ 0 ] . data_type )
72+ expect ( updateGlobal . schema [ 0 ] . display_name ) . to . be . equal ( createGlobalField . global_field . schema [ 0 ] . display_name )
8173 done ( )
8274 } )
8375 . catch ( done )
@@ -142,7 +134,7 @@ describe('Global Field api Test', () => {
142134 // it('should create nested global field for reference', done => {
143135 // makeGlobalField({ api_version: '3.2' }).create(createNestedGlobalFieldForReference)
144136 // .then(globalField => {
145- // expect(globalField.global_field. uid).to.be.equal(createNestedGlobalFieldForReference.global_field.uid);
137+ // expect(globalField.uid).to.be.equal(createNestedGlobalFieldForReference.global_field.uid);
146138 // done();
147139 // })
148140 // .catch(err => {
@@ -154,7 +146,7 @@ describe('Global Field api Test', () => {
154146 // it('should create nested global field', done => {
155147 // makeGlobalField({ api_version: '3.2' }).create(createNestedGlobalField)
156148 // .then(globalField => {
157- // expect(globalField.global_field. uid).to.be.equal(createNestedGlobalField.global_field.uid);
149+ // expect(globalField.uid).to.be.equal(createNestedGlobalField.global_field.uid);
158150 // done();
159151 // })
160152 // .catch(err => {
@@ -166,7 +158,7 @@ describe('Global Field api Test', () => {
166158 // it('should fetch nested global field', done => {
167159 // makeGlobalField(createNestedGlobalField.global_field.uid, { api_version: '3.2' }).fetch()
168160 // .then(globalField => {
169- // expect(globalField.global_field. uid).to.be.equal(createNestedGlobalField.global_field.uid);
161+ // expect(globalField.uid).to.be.equal(createNestedGlobalField.global_field.uid);
170162 // done();
171163 // })
172164 // .catch(err => {
@@ -175,16 +167,39 @@ describe('Global Field api Test', () => {
175167 // });
176168 // });
177169
178- // it('should update nested global fields without fetch', done => {
179- // makeGlobalField(createNestedGlobalField.global_field.uid, { api_version: '3.2' })
180- // .update(createNestedGlobalField)
170+ // it('should fetch and update nested global Field', done => {
171+ // makeGlobalField(createGlobalField.global_field.uid, { api_version: '3.2' }).fetch()
181172 // .then((globalField) => {
182- // expect(globalField.global_field.schema.length).to.be.equal(2)
173+ // globalField.title = 'Update title'
174+ // return globalField.update()
175+ // })
176+ // .then((updateGlobal) => {
177+ // expect(updateGlobal.uid).to.be.equal(createGlobalField.global_field.uid)
178+ // expect(updateGlobal.title).to.be.equal('Update title')
179+ // expect(updateGlobal.schema[0].uid).to.be.equal(createGlobalField.global_field.schema[0].uid)
180+ // expect(updateGlobal.schema[0].data_type).to.be.equal(createGlobalField.global_field.schema[0].data_type)
181+ // expect(updateGlobal.schema[0].display_name).to.be.equal(createGlobalField.global_field.schema[0].display_name)
183182 // done()
184183 // })
185184 // .catch(done)
186185 // })
187186
187+ // it('should update nested global Field', done => {
188+ // const globalField = makeGlobalField(createGlobalField.global_field.uid, { api_version: '3.2' })
189+ // Object.assign(globalField, cloneDeep(createGlobalField.global_field))
190+ // globalField.update()
191+ // .then((updateGlobal) => {
192+ // expect(updateGlobal.uid).to.be.equal(createGlobalField.global_field.uid)
193+ // expect(updateGlobal.title).to.be.equal(createGlobalField.global_field.title)
194+ // expect(updateGlobal.schema[0].uid).to.be.equal(createGlobalField.global_field.schema[0].uid)
195+ // expect(updateGlobal.schema[0].data_type).to.be.equal(createGlobalField.global_field.schema[0].data_type)
196+ // expect(updateGlobal.schema[0].display_name).to.be.equal(createGlobalField.global_field.schema[0].display_name)
197+ // done()
198+ // })
199+ // .catch(done)
200+ // })
201+
202+
188203 // it("should delete nested global field", (done) => {
189204 // makeGlobalField(createNestedGlobalField.global_field.uid, { api_version: '3.2' })
190205 // .delete()
0 commit comments