Skip to content

Commit

Permalink
test(description): add test for convert function
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSaba committed Feb 8, 2024
1 parent 063de58 commit de32785
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion src/test/description.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from '@jest/globals'
import { Descriptions, LocalizedJSONSchema } from '../types'
import { getDescriptions, getLocalizedDescription } from '..'
import { convertToJsonSchema, getDescriptions, getLocalizedDescription } from '../description'

const description: string = 'test description'
const englishDescription: string = 'english description'
Expand All @@ -19,6 +19,17 @@ const schemaWithoutDescription: LocalizedJSONSchema = {
const schemaWithoutDescriptions: LocalizedJSONSchema = {
description
}
const nestedSchemas: LocalizedJSONSchema = {
description,
descriptions,
items: [fullSchema, schemaWithoutDescription],
additionalItems: false,
contains: fullSchema,
properties: {
test1: schemaWithoutDescriptions,
test2: fullSchema
}
}

describe('Full schema', () => {
test('Descriptions', () => {
Expand All @@ -31,6 +42,12 @@ describe('Full schema', () => {
expect(english).toMatch(englishDescription)
expect(french).toMatch(frenchDescription)
})
test('Convert schema', () => {
const englishSchema = convertToJsonSchema(fullSchema, 'en')
const frenchSchema = convertToJsonSchema(fullSchema, 'fr')
expect(englishSchema).toMatchObject({ description: englishDescription })
expect(frenchSchema).toMatchObject({ description: frenchDescription })
})
})

describe('Schema without description', () => {
Expand All @@ -44,6 +61,12 @@ describe('Schema without description', () => {
expect(english).toMatch(englishDescription)
expect(french).toMatch(frenchDescription)
})
test('Convert schema', () => {
const englishSchema = convertToJsonSchema(schemaWithoutDescription, 'en')
const frenchSchema = convertToJsonSchema(schemaWithoutDescription, 'fr')
expect(englishSchema).toMatchObject({ description: englishDescription })
expect(frenchSchema).toMatchObject({ description: frenchDescription })
})
})

describe('Schema without descriptions', () => {
Expand All @@ -57,4 +80,47 @@ describe('Schema without descriptions', () => {
expect(english).toMatch(description)
expect(french).toBeUndefined()
})
test('Convert schema', () => {
const englishSchema = convertToJsonSchema(schemaWithoutDescriptions, 'en')
const frenchSchema = convertToJsonSchema(schemaWithoutDescriptions, 'fr')
expect(englishSchema).toMatchObject({ description })
expect(frenchSchema).toMatchObject({ description })
})
})

describe('Nested schemas', () => {
test('Descriptions', () => {
const localizedDescriptions: Descriptions = getDescriptions(nestedSchemas)
expect(localizedDescriptions).toMatchObject(descriptions)
})
test('Localized description', () => {
const english = getLocalizedDescription(nestedSchemas, 'en')
const french = getLocalizedDescription(nestedSchemas, 'fr')
expect(english).toMatch(englishDescription)
expect(french).toMatch(frenchDescription)
})
test('Convert schema', () => {
const englishSchema = convertToJsonSchema(nestedSchemas, 'en')
const frenchSchema = convertToJsonSchema(nestedSchemas, 'fr')
expect(englishSchema).toMatchObject({
description: englishDescription,
items: [{ description: englishDescription }, { description: englishDescription }],
additionalItems: false,
contains: { description: englishDescription },
properties: {
test1: { description },
test2: { description: englishDescription }
}
})
expect(frenchSchema).toMatchObject({
description: frenchDescription,
items: [{ description: frenchDescription }, { description: frenchDescription }],
additionalItems: false,
contains: { description: frenchDescription },
properties: {
test1: { description },
test2: { description: frenchDescription }
}
})
})
})

0 comments on commit de32785

Please sign in to comment.