Changeset View
Changeset View
Standalone View
Standalone View
lib/types/validation.test.js
// @flow | // @flow | ||||
import _findKey from 'lodash/fp/findKey.js'; | import _findKey from 'lodash/fp/findKey.js'; | ||||
import { rawEntryInfoValidator } from './entry-types.js'; | |||||
import { | import { | ||||
imageValidator, | imageValidator, | ||||
videoValidator, | videoValidator, | ||||
mediaValidator, | mediaValidator, | ||||
} from './media-types.js'; | } from './media-types.js'; | ||||
import { messageTypes } from './message-types-enum.js'; | import { messageTypes } from './message-types-enum.js'; | ||||
import { threadTypes, rawThreadInfoValidator } from './thread-types.js'; | import { threadTypes, rawThreadInfoValidator } from './thread-types.js'; | ||||
import { messageSpecs } from '../shared/messages/message-specs.js'; | import { messageSpecs } from '../shared/messages/message-specs.js'; | ||||
▲ Show 20 Lines • Show All 615 Lines • ▼ Show 20 Lines | it('should validate correct thread', () => { | ||||
expect(rawThreadInfoValidator.is(thread)).toBe(true); | expect(rawThreadInfoValidator.is(thread)).toBe(true); | ||||
}); | }); | ||||
it('should not validate incorrect thread', () => { | it('should not validate incorrect thread', () => { | ||||
expect( | expect( | ||||
rawThreadInfoValidator.is({ ...thread, creationTime: undefined }), | rawThreadInfoValidator.is({ ...thread, creationTime: undefined }), | ||||
).toBe(false); | ).toBe(false); | ||||
}); | }); | ||||
}); | }); | ||||
describe('entry validation', () => { | |||||
const entry = { | |||||
id: '92860', | |||||
threadID: '85068', | |||||
text: 'text', | |||||
year: 2023, | |||||
month: 4, | |||||
day: 2, | |||||
creationTime: 1682082939882, | |||||
creatorID: '83853', | |||||
deleted: false, | |||||
}; | |||||
it('should validate correct entry', () => { | |||||
expect(rawEntryInfoValidator.is(entry)).toBe(true); | |||||
}); | |||||
it('should not validate incorrect entry', () => { | |||||
expect(rawEntryInfoValidator.is({ ...entry, threadID: 0 })).toBe(false); | |||||
}); | |||||
}); |