kosmos/akkounts-api
kosmos
/
akkounts-api
Archived
8
1
Fork 0
This repository has been archived on 2022-09-21. You can view files and clone it, but cannot push or open issues or pull requests.
akkounts-api/spec/routes/accounts/mastodon/btcpay_hook.spec.ts

70 lines
1.7 KiB
TypeScript

import { expect } from 'chai'
import { supertest, sandbox, factory, setup } from '../../../spec_helper'
import BaseRoute from '../../../../app/routes/base'
setup()
describe('POST /accounts/mastodon/btcpay_hook', () => {
before(() => {
process.env.BTCPAY_WEBHOOK_TOKEN = 'supersecure'
})
describe('auth token missing', () => {
it('returns an error', async () => {
await supertest
.post('/accounts/mastodon/btcpay_hook')
.set('Content-Type', 'application/json')
.send({ status: 'confirmed' })
.expect(401)
.then(res => {
expect(res.body.error.message).to.eq('Unauthorized')
})
})
})
describe('auth token is invalid', () => {
it('returns an error', async () => {
await supertest
.post('/accounts/mastodon/btcpay_hook?token=123456')
.set('Content-Type', 'application/json')
.send({ status: 'confirmed' })
.expect(401)
.then(res => {
expect(res.body.error.message).to.eq('Unauthorized')
})
})
})
describe('successful request', () => {
before(() => {
sandbox
.stub(BaseRoute.prototype, 'createMastodonClient')
.returns({
post: url => {
return Promise.resolve({
data: { code: '123abc' }
})
}
})
})
it('returns an error', async () => {
await supertest
.post('/accounts/mastodon/btcpay_hook?token=supersecure')
.set('Content-Type', 'application/json')
.send({
buyerFields: {
buyerEmail: 'satoshi@kosmos.org'
},
status: 'confirmed'
})
.expect(200)
.then(res => {
expect(res.body.status).to.eq('OK')
})
})
})
})