kosmos/akkounts-api
kosmos
/
akkounts-api
Archived
8
1
Fork 0

Fix BTCPay webhook not returning response

Adds a test for successful Webhook responses and fixes the missing
return.
This commit is contained in:
Basti 2019-10-18 15:35:14 +02:00
parent c8a38e4d78
commit 4518cc84c2
No known key found for this signature in database
GPG Key ID: BE4634D632D39B67
2 changed files with 37 additions and 1 deletions

View File

@ -36,13 +36,15 @@ class MastodonBtcPayHookRoute extends BaseRoute {
content: message
}).then(() => res.status(200))
.catch(err => this.handleError(res, err))
return res.status(200).json({ status: 'OK' })
}
private createMessage (inviteCode: String) {
const inviteUrl = `${process.env.MASTODON_HOST}/invite/${inviteCode}`
const message = 'Here\'s your invite link for creating an account on kosmos.social:'
+ `\n\n${inviteUrl}\n\n`
+ 'Thanks a lot for supporting community service providers!'
+ 'Welcome to the community!'
return message
}

View File

@ -6,6 +6,10 @@ 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
@ -32,4 +36,34 @@ describe('POST /accounts/mastodon/btcpay_hook', () => {
})
})
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')
})
})
})
})