@dev-crew-berlin/enter-js-utils 0.98.9 → 0.98.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -693,4 +693,56 @@ describe('getAttendeeList', () => {
|
|
|
693
693
|
if (!result.success) return;
|
|
694
694
|
expect(result.data.eventCursor).toBe('abc123');
|
|
695
695
|
});
|
|
696
|
+
});
|
|
697
|
+
describe('createEvents', () => {
|
|
698
|
+
afterEach(() => {
|
|
699
|
+
vi.restoreAllMocks();
|
|
700
|
+
});
|
|
701
|
+
it('returns created and eventCursors populated from response body', async () => {
|
|
702
|
+
vi.stubGlobal('fetch', () => Promise.resolve(new Response(JSON.stringify({
|
|
703
|
+
created: 2,
|
|
704
|
+
event_cursors: {
|
|
705
|
+
'uuid-1': 'cursor-abc',
|
|
706
|
+
'uuid-2': 'cursor-def'
|
|
707
|
+
}
|
|
708
|
+
}), {
|
|
709
|
+
status: 201
|
|
710
|
+
})));
|
|
711
|
+
const api = makeFullAPI();
|
|
712
|
+
const result = await api.createEvents([]);
|
|
713
|
+
expect(result.success).toBe(true);
|
|
714
|
+
if (!result.success) return;
|
|
715
|
+
expect(result.data.created).toBe(2);
|
|
716
|
+
expect(result.data.eventCursors).toEqual({
|
|
717
|
+
'uuid-1': 'cursor-abc',
|
|
718
|
+
'uuid-2': 'cursor-def'
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
it('returns empty eventCursors when field is absent', async () => {
|
|
722
|
+
vi.stubGlobal('fetch', () => Promise.resolve(new Response(JSON.stringify({
|
|
723
|
+
created: 1
|
|
724
|
+
}), {
|
|
725
|
+
status: 201
|
|
726
|
+
})));
|
|
727
|
+
const api = makeFullAPI();
|
|
728
|
+
const result = await api.createEvents([]);
|
|
729
|
+
expect(result.success).toBe(true);
|
|
730
|
+
if (!result.success) return;
|
|
731
|
+
expect(result.data.created).toBe(1);
|
|
732
|
+
expect(result.data.eventCursors).toEqual({});
|
|
733
|
+
});
|
|
734
|
+
it('returns empty eventCursors when field is empty', async () => {
|
|
735
|
+
vi.stubGlobal('fetch', () => Promise.resolve(new Response(JSON.stringify({
|
|
736
|
+
created: 0,
|
|
737
|
+
event_cursors: {}
|
|
738
|
+
}), {
|
|
739
|
+
status: 201
|
|
740
|
+
})));
|
|
741
|
+
const api = makeFullAPI();
|
|
742
|
+
const result = await api.createEvents([]);
|
|
743
|
+
expect(result.success).toBe(true);
|
|
744
|
+
if (!result.success) return;
|
|
745
|
+
expect(result.data.created).toBe(0);
|
|
746
|
+
expect(result.data.eventCursors).toEqual({});
|
|
747
|
+
});
|
|
696
748
|
});
|
|
@@ -163,7 +163,10 @@ declare class API extends APIBase {
|
|
|
163
163
|
/**
|
|
164
164
|
* @category Events
|
|
165
165
|
*/
|
|
166
|
-
createEvents(args: EventInput[], options?: FetchOptions): Promise<APIResult<
|
|
166
|
+
createEvents(args: EventInput[], options?: FetchOptions): Promise<APIResult<{
|
|
167
|
+
created: number;
|
|
168
|
+
eventCursors: Record<string, string>;
|
|
169
|
+
}>>;
|
|
167
170
|
/**
|
|
168
171
|
* Subscribe to the SSE event stream. Yields events as they arrive.
|
|
169
172
|
* Use `for await` to consume events, and `break` or `return` to unsubscribe.
|
package/dist/api-client/index.js
CHANGED
|
@@ -228,7 +228,18 @@ class API extends APIBase {
|
|
|
228
228
|
* @category Events
|
|
229
229
|
*/
|
|
230
230
|
async createEvents(args, options = {}) {
|
|
231
|
-
|
|
231
|
+
const result = await this.fetchResponse(`/events`, {
|
|
232
|
+
method: 'POST',
|
|
233
|
+
headers: this.buildHeaders(),
|
|
234
|
+
body: JSON.stringify(args),
|
|
235
|
+
...options
|
|
236
|
+
});
|
|
237
|
+
if (!result.success) return result;
|
|
238
|
+
const json = await result.data.json();
|
|
239
|
+
return success({
|
|
240
|
+
created: json.created,
|
|
241
|
+
eventCursors: json.event_cursors ?? {}
|
|
242
|
+
});
|
|
232
243
|
}
|
|
233
244
|
|
|
234
245
|
/**
|