diff --git a/jest.config.js b/jest.config.js index 4c2b6ba7f..0e517b35b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,5 +8,10 @@ module.exports = { moduleNameMapper: { 'src/(.*)': '/src/$1', }, + globals: { + 'ts-jest': { + tsConfig: 'tsconfig.test.json', + }, + }, setupFilesAfterEnv: ['./test.setup.ts'], }; diff --git a/src/blocks/types/frontMatter.ts b/src/blocks/types/frontMatter.ts index 1b65c05fd..fada9771b 100644 --- a/src/blocks/types/frontMatter.ts +++ b/src/blocks/types/frontMatter.ts @@ -2,31 +2,36 @@ import { Author } from './author'; // All frontmatter props are optional in order to save storage and transfer payload size // When the values are null indicates it has been explicitly set to null. -export interface BlockFrontMatterProps { - authors?: Author[] | null; - licenses?: { content: string | null; code: string | null } | null; - doi?: string | null; - open_access?: boolean | null; - github?: string | null; - binder?: string | null; - subtitle?: string | null; - short_title?: string | null; - venue?: { title?: string; url?: string } | null; - biblio?: { + +export type FrontMatterProps = { + authors: Author[] | null; + licenses: { content: string | null; code: string | null } | null; + doi: string | null; + arxiv: string | null; + open_access: boolean | null; + github: string | null; + binder: string | null; + subtitle: string | null; + short_title: string | null; + venue: { title?: string; url?: string } | null; + biblio: { volume?: string; issue?: string; first_page?: string; last_page?: string; } | null; -} +}; + +export type BlockFrontMatterProps = Partial; export type ProjectFrontMatterProps = Omit; -// TODO: ensure exhausiveness +// Exhausiveness is ensured in test export const PROJECT_FRONT_MATTER_KEYS = [ 'authors', 'licenses', 'doi', + 'arxiv', 'open_access', 'github', 'binder', diff --git a/src/blocks/utils.spec.ts b/src/blocks/utils.spec.ts index ab223c30b..3bec6f56d 100644 --- a/src/blocks/utils.spec.ts +++ b/src/blocks/utils.spec.ts @@ -1,4 +1,4 @@ -import { BlockFrontMatterProps, ProjectFrontMatterProps } from './types'; +import { BlockFrontMatterProps, FrontMatterProps, ProjectFrontMatterProps } from './types'; import { extractBlockFrontMatter, extractProjectFrontMatter } from './utils'; export const TEST_PROJECT_FRONT_MATTER: ProjectFrontMatterProps = { @@ -19,7 +19,7 @@ export const TEST_BLOCK_FRONT_MATTER: BlockFrontMatterProps = { }; const TEST_FRONT_MATTER_OBJ = { - authors: [{ test: 'test' }], + authors: [], license: undefined, // handles undefined github: null, short_title: '', @@ -30,6 +30,26 @@ const TEST_FRONT_MATTER_OBJ = { }; describe('extractBlockFrontMatter', () => { + test('should handle correct frontmatter extraction exhausively', () => { + const frontmatter: FrontMatterProps = { + authors: [], + licenses: { content: 'MIT', code: null }, + github: null, + doi: 'doi', + arxiv: 'arxiv', + binder: 'binder', + subtitle: 'subtitle', + short_title: '', + open_access: false, + venue: {}, + biblio: {}, + }; + + expect(extractBlockFrontMatter(frontmatter)).toEqual(frontmatter); + const { venue, biblio, ...projectExtractionResult } = frontmatter; + expect(extractProjectFrontMatter(frontmatter)).toEqual(projectExtractionResult); + }); + test('should extract block front matter properly', () => { const target = { ...TEST_FRONT_MATTER_OBJ }; diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 000000000..a8d4317b4 --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": [] +}