forked from cameri/nostream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlnbits-callback-schema.spec.ts
More file actions
37 lines (32 loc) · 1.72 KB
/
Copy pathlnbits-callback-schema.spec.ts
File metadata and controls
37 lines (32 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { lnbitsCallbackBodySchema, lnbitsCallbackQuerySchema } from '../../../src/schemas/lnbits-callback-schema'
import { expect } from 'chai'
import { validateSchema } from '../../../src/utils/validation'
describe('LNbits Callback Schema', () => {
describe('lnbitsCallbackQuerySchema', () => {
it('returns no error if hmac is valid', () => {
const query = { hmac: '1660306803:fa4dd948576fe182f5d0e3120b9df42c83dffa1c884754d5e4d3b0a2f98a01c5' }
const result = validateSchema(lnbitsCallbackQuerySchema)(query)
expect(result.error).to.be.undefined
expect(result.value).to.deep.include(query)
})
it('returns error if hmac is missing', () => {
const result = validateSchema(lnbitsCallbackQuerySchema)({})
expect(result.error).to.have.nested.property('message', '"hmac" is required')
})
it('returns error if hmac format is invalid', () => {
const result = validateSchema(lnbitsCallbackQuerySchema)({ hmac: 'not-an-hmac' })
expect(result.error).to.have.nested.property('message').that.matches(/"hmac" with value "not-an-hmac" fails to match the required pattern/)
})
})
describe('lnbitsCallbackBodySchema', () => {
it('returns no error if payment_hash is valid', () => {
const body = { payment_hash: 'fa4dd948576fe182f5d0e3120b9df42c83dffa1c884754d5e4d3b0a2f98a01c5' }
const result = validateSchema(lnbitsCallbackBodySchema)(body)
expect(result.error).to.be.undefined
})
it('returns error if payment_hash is not 64 chars hex', () => {
const result = validateSchema(lnbitsCallbackBodySchema)({ payment_hash: 'abc' })
expect(result.error).to.have.nested.property('message', '"payment_hash" length must be 64 characters long')
})
})
})