pzp-db/test/feed-v1-invalid-type.test.js

100 lines
1.9 KiB
JavaScript

const tape = require('tape')
const FeedV1 = require('../lib/feed-v1')
const { generateKeypair } = require('./util')
tape('invalid type not a string', (t) => {
const keys = generateKeypair('alice')
t.throws(
() => {
FeedV1.create({
keys,
content: { text: 'Hello world!' },
when: 1652037377204,
type: 123,
existing: new Map(),
})
},
/type is not a string/,
'invalid type if contains /'
)
t.end()
})
tape('invalid type with "/" character', (t) => {
const keys = generateKeypair('alice')
t.throws(
() => {
FeedV1.create({
keys,
content: { text: 'Hello world!' },
when: 1652037377204,
type: 'group/init',
existing: new Map(),
})
},
/invalid type/,
'invalid type if contains /'
)
t.end()
})
tape('invalid type with "*" character', (t) => {
const keys = generateKeypair('alice')
t.throws(
() => {
FeedV1.create({
keys,
content: { text: 'Hello world!' },
when: 1652037377204,
type: 'star*',
existing: new Map(),
})
},
/invalid type/,
'invalid type if contains *'
)
t.end()
})
tape('invalid type too short', (t) => {
const keys = generateKeypair('alice')
t.throws(
() => {
FeedV1.create({
keys,
content: { text: 'Hello world!' },
when: 1652037377204,
type: 'xy',
existing: new Map(),
})
},
/shorter than 3/,
'invalid type if too short'
)
t.end()
})
tape('invalid type too long', (t) => {
const keys = generateKeypair('alice')
t.throws(
() => {
FeedV1.create({
keys,
content: { text: 'Hello world!' },
when: 1652037377204,
type: 'a'.repeat(120),
existing: new Map(),
})
},
/100\+ characters long/,
'invalid type if too long'
)
t.end()
})