Skip to content

Commit

Permalink
fix: add missing fields to Story object
Browse files Browse the repository at this point in the history
Co-authored-by: =?UTF-8?q?Finn=20B=C3=B6ger?= <[email protected]>
  • Loading branch information
edodusi and finnboeger committed Dec 30, 2024
1 parent 060dd69 commit 8d7b0ae
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 6 deletions.
89 changes: 88 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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();
});
});
});
28 changes: 23 additions & 5 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,31 @@ export interface ISbComponentType<T extends string> {
_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<string> & { [index: string]: any },
> extends ISbMultipleStoriesData {
alternates: ISbAlternateObject[];
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;
Expand All @@ -104,24 +118,28 @@ 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[];
translated_slugs?: {
path: string;
name: string | null;
lang: ISbStoryData['lang'];
}[];
}[] | null;
unpublished_changes?: boolean;
updated_at?: string;
uuid: string;
Expand Down

0 comments on commit 8d7b0ae

Please sign in to comment.