diff --git a/src/index.test.ts b/src/index.test.ts index 2ae88d9f..f51fb771 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; import type { ResponseFn } from './sbFetch'; import SbFetch from './sbFetch'; import { SbHelpers } from './sbHelpers'; -import type { ISbLink } from './interfaces'; +import type { ISbLink, ISbStoryData } from './interfaces'; // Mocking external dependencies vi.mock('../src/sbFetch', () => { @@ -1041,4 +1041,91 @@ describe('storyblokClient', () => { expect(mockGet).toHaveBeenCalledTimes(1); }); }); + + // eslint-disable-next-line test/prefer-lowercase-title + describe('ISbStoryData interface implementation', () => { + it('should validate a complete story object structure', () => { + const storyData: ISbStoryData = { + alternates: [], + content: { + _uid: 'test-uid', + component: 'test', + }, + created_at: '2024-01-01T00:00:00.000Z', + deleted_at: undefined, + full_slug: 'test/story', + group_id: 'test-group', + id: 1, + is_startpage: false, + lang: 'default', + meta_data: {}, + name: 'Test Story', + parent_id: null, + position: 0, + published_at: null, + slug: 'test-story', + sort_by_date: null, + tag_list: [], + uuid: 'test-uuid', + }; + + expect(storyData).toBeDefined(); + expect(storyData).toMatchObject({ + alternates: expect.any(Array), + content: expect.objectContaining({ + _uid: expect.any(String), + component: expect.any(String), + }), + created_at: expect.any(String), + full_slug: expect.any(String), + group_id: expect.any(String), + id: expect.any(Number), + lang: expect.any(String), + name: expect.any(String), + position: expect.any(Number), + slug: expect.any(String), + uuid: expect.any(String), + }); + }); + + it('should handle optional properties correctly', () => { + const storyData: ISbStoryData = { + alternates: [], + content: { + _uid: 'test-uid', + component: 'test', + }, + created_at: '2024-01-01T00:00:00.000Z', + full_slug: 'test/story', + group_id: 'test-group', + id: 1, + lang: 'default', + meta_data: {}, + name: 'Test Story', + position: 0, + published_at: null, + slug: 'test-story', + sort_by_date: null, + tag_list: [], + uuid: 'test-uuid', + parent_id: null, + // Optional properties + preview_token: { + token: 'test-token', + timestamp: '2024-01-01T00:00:00.000Z', + }, + localized_paths: [ + { + path: '/en/test', + name: 'Test EN', + lang: 'en', + published: true, + }, + ], + }; + + expect(storyData.preview_token).toBeDefined(); + expect(storyData.localized_paths).toBeDefined(); + }); + }); }); diff --git a/src/interfaces.ts b/src/interfaces.ts index 7fd34c55..0a398361 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -82,6 +82,18 @@ export interface ISbComponentType { _editable?: string; } +export interface PreviewToken { + token: string; + timestamp: string; +} + +export interface LocalizedPath { + path: string; + name: string | null; + lang: string; + published: boolean; +} + export interface ISbStoryData< Content = ISbComponentType & { [index: string]: any }, > extends ISbMultipleStoriesData { @@ -89,10 +101,12 @@ export interface ISbStoryData< breadcrumbs?: ISbLinkURLObject[]; content: Content; created_at: string; - default_full_slug?: string; + deleted_at?: string; + default_full_slug?: string | null; default_root?: string; disble_fe_editor?: boolean; - first_published_at?: string; + favourite_for_user_ids?: number[] | null; + first_published_at?: string | null; full_slug: string; group_id: string; id: number; @@ -104,16 +118,20 @@ export interface ISbStoryData< id: number; userid: string; }; + last_author_id?: number; + localized_paths?: LocalizedPath[] | null; meta_data: any; name: string; parent?: ISbStoryData; - parent_id: number; + parent_id: number | null; path?: string; pinned?: '1' | boolean; position: number; + preview_token?: PreviewToken; published?: boolean; published_at: string | null; - release_id?: number; + release_id?: number | null; + scheduled_date?: string | null; slug: string; sort_by_date: string | null; tag_list: string[]; @@ -121,7 +139,7 @@ export interface ISbStoryData< path: string; name: string | null; lang: ISbStoryData['lang']; - }[]; + }[] | null; unpublished_changes?: boolean; updated_at?: string; uuid: string;