You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it('should notifiy because sys information is missing',()=>{
70
+
constliveUpdates=newLiveUpdates();
71
+
constdata={title: 'Data 1',__typename: 'Demo'};
72
+
constcb=vi.fn();
73
+
74
+
liveUpdates.subscribe(data,locale,cb);
75
+
76
+
expect(helpers.debug.error).toHaveBeenCalledWith(
77
+
'Live Updates requires the "sys.id" to be present on the provided data',
78
+
data
79
+
);
80
+
});
81
+
82
+
it('should notifiy because we dont know if it is REST or GraphQL',()=>{
83
+
constliveUpdates=newLiveUpdates();
84
+
constdata={sys: {id: '1'},title: 'Data 1'};
85
+
constcb=vi.fn();
86
+
87
+
liveUpdates.subscribe(data,locale,cb);
88
+
89
+
expect(helpers.debug.error).toHaveBeenCalledWith(
90
+
'For live updates as a basic requirement the provided data must include the "fields" property for REST or "__typename" for Graphql, otherwise the data will be treated as invalid and live updates will not work.',
91
+
data
92
+
);
93
+
});
94
+
});
95
+
54
96
it('no longer receives updates after unsubcribing',()=>{
* Is it GraphQL or REST and does it contain the sys information
216
+
* TODO: add more accurate checks
217
+
*/
218
+
privatevalidateDataFromPreview(data: Argument){
219
+
constdataAsString=JSON.stringify(data);
220
+
221
+
constisGQL=dataAsString.includes('__typename');
222
+
constisREST=dataAsString.includes('fields":{');
223
+
consthasSys=dataAsString.includes('sys":{');
224
+
225
+
letisValid=true;
226
+
227
+
if(!hasSys){
228
+
isValid=false;
229
+
debug.error('Live Updates requires the "sys.id" to be present on the provided data',data);
230
+
}
231
+
232
+
if(!isGQL&&!isREST){
233
+
isValid=false;
234
+
debug.error(
235
+
'For live updates as a basic requirement the provided data must include the "fields" property for REST or "__typename" for Graphql, otherwise the data will be treated as invalid and live updates will not work.',
236
+
data
237
+
);
238
+
}
239
+
240
+
return{
241
+
isGQL,
242
+
isREST,
243
+
hasSys,
244
+
isValid,
245
+
};
246
+
}
247
+
213
248
/**
214
249
* Subscribe to data changes from the Editor, returns a function to unsubscribe
215
250
* Will be called once initially for the restored data
0 commit comments