From e6ea647be8c2a835807927077d71802cdbc9bec8 Mon Sep 17 00:00:00 2001 From: Nicolas Van Labeke Date: Mon, 9 Dec 2024 14:33:25 +0000 Subject: [PATCH] test(28664): add tests --- .../utils/topic-filter.schema.spec.ts | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/hivemq-edge/src/frontend/src/modules/TopicFilters/utils/topic-filter.schema.spec.ts b/hivemq-edge/src/frontend/src/modules/TopicFilters/utils/topic-filter.schema.spec.ts index cc1417157..860438a72 100644 --- a/hivemq-edge/src/frontend/src/modules/TopicFilters/utils/topic-filter.schema.spec.ts +++ b/hivemq-edge/src/frontend/src/modules/TopicFilters/utils/topic-filter.schema.spec.ts @@ -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 @@ -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({ + status: 'warning', + message: expect.stringContaining(''), + }) + }) + + it('should return an error', () => { expect( - decodeDataUriJsonSchema( - 'data:application/json;base64,IHsKICAgICJ0eXBlIiA6ICJvYmplY3QiLAogICAgInByb3BlcnRpZXMiIDogewogICAgICAiZGVmaW5pdGlvbiIgOiB7CiAgICAgICAgInR5cGUiIDogIm9iamVjdCIsCiAgICAgICAgInByb3BlcnRpZXMiIDogewogICAgICAgICAgImRhdGFUeXBlIiA6IHsKICAgICAgICAgICAgInR5cGUiIDogInN0cmluZyIsCiAgICAgICAgICAgICJlbnVtIiA6IFsgIk5VTEwiLCAiQk9PTCIsICJCWVRFIiwgIldPUkQiLCAiRFdPUkQiLCAiTFdPUkQiLCAiVVNJTlQiLCAiVUlOVCIsICJVRElOVCIsICJVTElOVCIsICJTSU5UIiwgIklOVCIsICJESU5UIiwgIkxJTlQiLCAiUkVBTCIsICJMUkVBTCIsICJDSEFSIiwgIldDSEFSIiwgIlNUUklORyIsICJXU1RSSU5HIiwgIlRJTUUiLCAiTFRJTUUiLCAiREFURSIsICJMREFURSIsICJUSU1FX09GX0RBWSIsICJMVElNRV9PRl9EQVkiLCAiREFURV9BTkRfVElNRSIsICJMREFURV9BTkRfVElNRSIsICJSQVdfQllURV9BUlJBWSIgXSwKICAgICAgICAgICAgInRpdGxlIiA6ICJEYXRhIFR5cGUiLAogICAgICAgICAgICAiZGVzY3JpcHRpb24iIDogIlRoZSBleHBlY3RlZCBkYXRhIHR5cGUgb2YgdGhlIHRhZyIsCiAgICAgICAgICAgICJlbnVtTmFtZXMiIDogWyAiTnVsbCIsICJCb29sZWFuIiwgIkJ5dGUiLCAiV29yZCAodW5pdCAxNikiLCAiRFdvcmQgKHVpbnQgMzIpIiwgIkxXb3JkICh1aW50IDY0KSIsICJVU2ludCAodWludCA4KSIsICJVaW50ICh1aW50IDE2KSIsICJVRGludCAodWludCAzMikiLCAiVUxpbnQgKHVpbnQgNjQpIiwgIlNpbnQgKGludCA4KSIsICJJbnQgKGludCAxNikiLCAiRGludCAoaW50IDMyKSIsICJMaW50IChpbnQgNjQpIiwgIlJlYWwgKGZsb2F0IDMyKSIsICJMUmVhbCAoZG91YmxlIDY0KSIsICJDaGFyICgxIGJ5dGUgY2hhcikiLCAiV0NoYXIgKDIgYnl0ZSBjaGFyKSIsICJTdHJpbmciLCAiV1N0cmluZyIsICJUaW1pbmcgKER1cmF0aW9uIG1zKSIsICJMb25nIFRpbWluZyAoRHVyYXRpb24gbnMpIiwgIkRhdGUgKERhdGVTdGFtc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gfSwKICAgICJyZXF1aXJlZCIgOiBbICJkZWZpbml0aW9uIiwgImRlc2NyaXB0aW9uIiwgIm5hbWUiIF0KICB9Cg==' - ) - ).toBeFalsy + validateSchemaFromDataURI('data:application/json;base64,ewogICJ0ZXN0IjogMQp9Cg==') + ).toStrictEqual({ + 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({ + message: expect.stringContaining(''), + status: 'success', + schema: expect.objectContaining({}), + }) }) })