1
1
import path from 'path'
2
2
import { expect } from 'chai'
3
+ import { cloneDeep } from 'lodash'
3
4
import { describe , it , setup } from 'mocha'
4
5
import { jsonReader } from '../utility/fileOperations/readwrite'
5
- import { createGlobalField } from '../mock/globalfield'
6
+ import { createGlobalField , createNestedGlobalField , createNestedGlobalFieldForReference } from '../mock/globalfield'
6
7
import { contentstackClient } from '../utility/ContentstackClient.js'
7
8
import dotenv from 'dotenv'
8
9
@@ -59,25 +60,16 @@ describe('Global Field api Test', () => {
59
60
. catch ( done )
60
61
} )
61
62
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 ( )
65
67
. 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 )
81
73
done ( )
82
74
} )
83
75
. catch ( done )
@@ -142,7 +134,7 @@ describe('Global Field api Test', () => {
142
134
// it('should create nested global field for reference', done => {
143
135
// makeGlobalField({ api_version: '3.2' }).create(createNestedGlobalFieldForReference)
144
136
// .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);
146
138
// done();
147
139
// })
148
140
// .catch(err => {
@@ -154,7 +146,7 @@ describe('Global Field api Test', () => {
154
146
// it('should create nested global field', done => {
155
147
// makeGlobalField({ api_version: '3.2' }).create(createNestedGlobalField)
156
148
// .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);
158
150
// done();
159
151
// })
160
152
// .catch(err => {
@@ -166,7 +158,7 @@ describe('Global Field api Test', () => {
166
158
// it('should fetch nested global field', done => {
167
159
// makeGlobalField(createNestedGlobalField.global_field.uid, { api_version: '3.2' }).fetch()
168
160
// .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);
170
162
// done();
171
163
// })
172
164
// .catch(err => {
@@ -175,16 +167,39 @@ describe('Global Field api Test', () => {
175
167
// });
176
168
// });
177
169
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()
181
172
// .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)
183
182
// done()
184
183
// })
185
184
// .catch(done)
186
185
// })
187
186
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
+
188
203
// it("should delete nested global field", (done) => {
189
204
// makeGlobalField(createNestedGlobalField.global_field.uid, { api_version: '3.2' })
190
205
// .delete()
0 commit comments