Skip to content

Commit

Permalink
test(28664): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vanch3d committed Dec 9, 2024
1 parent 792787c commit e6ea647
Showing 1 changed file with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { describe, expect } from 'vitest'
import { decodeDataUriJsonSchema } from '@/modules/TopicFilters/utils/topic-filter.schema.ts'
import {
decodeDataUriJsonSchema,
SchemaHandler,
validateSchemaFromDataURI,
} from '@/modules/TopicFilters/utils/topic-filter.schema.ts'
import { MOCK_TOPIC_FILTER_SCHEMA_VALID } from '@/api/hooks/useTopicFilters/__handlers__'

interface Suite {
data: string
Expand All @@ -26,10 +31,33 @@ describe('decodeDataUriJsonSchema', () => {
})

it('should return a valid json object', () => {
expect(decodeDataUriJsonSchema(MOCK_TOPIC_FILTER_SCHEMA_VALID)).toBeFalsy
})
})

describe('validateSchemaFromDataURI', () => {
it('should return a warning if not assigned', () => {
expect(validateSchemaFromDataURI(undefined)).toStrictEqual<SchemaHandler>({
status: 'warning',
message: expect.stringContaining(''),
})
})

it('should return an error', () => {
expect(
decodeDataUriJsonSchema(
'data:application/json;base64,IHsKICAgICJ0eXBlIiA6ICJvYmplY3QiLAogICAgInByb3BlcnRpZXMiIDogewogICAgICAiZGVmaW5pdGlvbiIgOiB7CiAgICAgICAgInR5cGUiIDogIm9iamVjdCIsCiAgICAgICAgInByb3BlcnRpZXMiIDogewogICAgICAgICAgImRhdGFUeXBlIiA6IHsKICAgICAgICAgICAgInR5cGUiIDogInN0cmluZyIsCiAgICAgICAgICAgICJlbnVtIiA6IFsgIk5VTEwiLCAiQk9PTCIsICJCWVRFIiwgIldPUkQiLCAiRFdPUkQiLCAiTFdPUkQiLCAiVVNJTlQiLCAiVUlOVCIsICJVRElOVCIsICJVTElOVCIsICJTSU5UIiwgIklOVCIsICJESU5UIiwgIkxJTlQiLCAiUkVBTCIsICJMUkVBTCIsICJDSEFSIiwgIldDSEFSIiwgIlNUUklORyIsICJXU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gICAgICAgICAidGFnQWRkcmVzcyIgOiB7CiAgICAgICAgICAgICJ0eXBlIiA6ICJzdHJpbmciLAogICAgICAgICAgICAidGl0bGUiIDogIlRhZyBBZGRyZXNzIiwKICAgICAgICAgICAgImRlc2NyaXB0aW9uIiA6ICJUaGUgd2VsbCBmb3JtZWQgYWRkcmVzcyBvZiB0aGUgdGFnIHRvIHJlYWQiCiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICAicmVxdWlyZWQiIDogWyAiZGF0YVR5cGUiLCAidGFnQWRkcmVzcyIgXSwKICAgICAgICAidGl0bGUiIDogImRlZmluaXRpb24iLAogICAgICAgICJkZXNjcmlwdGlvbiIgOiAiVGhlIGFjdHVhbCBkZWZpbml0aW9uIG9mIHRoZSB0YWcgb24gdGhlIGRldmljZSIKICAgICAgfSwKICAgICAgImRlc2NyaXB0aW9uIiA6IHsKICAgICAgICAidHlwZSIgOiAic3RyaW5nIiwKICAgICAgICAidGl0bGUiIDogImRlc2NyaXB0aW9uIiwKICAgICAgICAiZGVzY3JpcHRpb24iIDogIkEgaHVtYW4gcmVhZGFibGUgZGVzY3JpcHRpb24gb2YgdGhlIHRhZyIKICAgICAgfSwKICAgICAgIm5hbWUiIDogewogICAgICAgICJ0eXBlIiA6ICJzdHJpbmciLAogICAgICAgICJ0aXRsZSIgOiAibmFtZSIsCiAgICAgICAgImRlc2NyaXB0aW9uIiA6ICJuYW1lIG9mIHRoZSB0YWcgdG8gYmUgdXNlZCBpbiBtYXBwaW5ncyIKICAgICAgfQogICAgfSwKICAgICJyZXF1aXJlZCIgOiBbICJkZWZpbml0aW9uIiwgImRlc2NyaXB0aW9uIiwgIm5hbWUiIF0KICB9Cg=='
)
).toBeFalsy
validateSchemaFromDataURI('data:application/json;base64,ewogICJ0ZXN0IjogMQp9Cg==')
).toStrictEqual<SchemaHandler>({
error: 'Not a valid JSONSchema: `properties` is missing',
message: expect.stringContaining(''),
status: 'error',
})
})

it('should return a schema', () => {
expect(validateSchemaFromDataURI(MOCK_TOPIC_FILTER_SCHEMA_VALID)).toStrictEqual<SchemaHandler>({
message: expect.stringContaining(''),
status: 'success',
schema: expect.objectContaining({}),
})
})
})

0 comments on commit e6ea647

Please sign in to comment.