@@ -3,7 +3,7 @@ import { expect } from 'chai'
33import { cloneDeep } from 'lodash'
44import { describe , it , setup } from 'mocha'
55import { jsonReader } from '../utility/fileOperations/readwrite'
6- import { createGlobalField } from '../mock/globalfield'
6+ import { createGlobalField , createNestedGlobalField } from '../mock/globalfield'
77import { contentstackClient } from '../utility/ContentstackClient.js'
88import dotenv from 'dotenv'
99
@@ -155,8 +155,8 @@ describe("Global Field api Test", () => {
155155 . catch ( done ) ;
156156 } ) ;
157157
158- it ( "should get all nested global field from Query" , ( done ) => {
159- makeGlobalField ( { api_version : " 3.2" } )
158+ it ( "should get all nested global fields from Query" , ( done ) => {
159+ makeGlobalField ( { api_version : ' 3.2' } )
160160 . query ( )
161161 . find ( )
162162 . then ( ( collection ) => {
@@ -171,18 +171,7 @@ describe("Global Field api Test", () => {
171171 } ) ;
172172
173173 it ( 'should create nested global field' , done => {
174- const payload = {
175- global_field : {
176- title : 'Nested Global Field' ,
177- uid : 'nested_global_field222' ,
178- schema : [
179- { data_type : 'text' , display_name : 'Single Line Textbox' , uid : 'single_line' } ,
180- { data_type : 'global_field' , display_name : 'Global' , uid : 'global_field' , reference_to : 'first' } ,
181- ] ,
182- } ,
183- } ;
184-
185- makeGlobalField ( { api_version : '3.2' } ) . create ( payload )
174+ makeGlobalField ( { api_version : '3.2' } ) . create ( createNestedGlobalField )
186175 . then ( globalField => {
187176 console . log ( 'Response:' , globalField ) ;
188177 expect ( globalField . uid ) . to . be . equal ( payload . global_field . uid ) ;
@@ -195,7 +184,7 @@ describe("Global Field api Test", () => {
195184 } ) ;
196185
197186 it ( 'should fetch nested global field' , done => {
198- makeGlobalField ( 'nested_global_field222' ) . fetch ( )
187+ makeGlobalField ( 'nested_global_field333' , { api_version : '3.2' } ) . fetch ( )
199188 . then ( globalField => {
200189 console . log ( 'Response:' , globalField ) ;
201190 expect ( globalField . uid ) . to . be . equal ( 'nested_global_field222' ) ;
@@ -207,8 +196,18 @@ describe("Global Field api Test", () => {
207196 } ) ;
208197 } ) ;
209198
199+ it ( 'should update nested global fields without fetch' , done => {
200+ makeGlobalField ( createNestedGlobalField . global_field . uid , { headers : { api_version : '3.2' } } )
201+ . updateNestedGlobalField ( createNestedGlobalField )
202+ . then ( ( globalField ) => {
203+ expect ( globalField . global_field . schema . length ) . to . be . equal ( 2 )
204+ done ( )
205+ } )
206+ . catch ( done )
207+ } )
208+
210209 it ( "should delete nested global field" , ( done ) => {
211- makeGlobalField ( "nested_global_field222" )
210+ makeGlobalField ( "nested_global_field333" , { api_version : '3.2' } )
212211 . delete ( )
213212 . then ( ( data ) => {
214213 console . log ( "Response:" , data ) ;
@@ -245,16 +244,12 @@ describe("Global Field api Test", () => {
245244function makeGlobalField ( globalFieldUid = null , options = { } ) {
246245 let uid = null ;
247246 let finalOptions = options ;
248- // If globalFieldUid is an object, treat it as options
249247 if ( typeof globalFieldUid === "object" ) {
250248 finalOptions = globalFieldUid ;
251249 } else {
252250 uid = globalFieldUid ;
253251 }
254- // Ensure finalOptions is always an object with default values
255252 finalOptions = finalOptions || { } ;
256-
257253 return client
258- . stack ( { api_key : process . env . API_KEY } )
259- . globalField ( uid , finalOptions ) ;
254+ . stack ( { api_key : process . env . API_KEY } ) . globalField ( uid , finalOptions ) ;
260255}
0 commit comments