Skip to content

Commit 14673ab

Browse files
committed
feat: improve ussd tests
1 parent 86e8a64 commit 14673ab

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

test/ussd.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,43 +47,39 @@ describe('USSD', function () {
4747
}))
4848
})
4949

50-
it('returns expected response', function (done) {
50+
it('returns response starting with CON or END', function (done) {
5151
request
5252
.post('/test-service')
53-
.send('hello')
54-
.expect('content-type', /text\/plain/i)
55-
.expect(200, function (err, resp) {
56-
if (err) throw err
57-
const match = resp.text.match(/^(CON)|(END)/)
58-
should(match).be.ok()
53+
.send({ text: 'hello', sessionId: '123', serviceCode: '*123#', phoneNumber: '+1234567890' })
54+
.expect('Content-Type', /text\/plain/i)
55+
.expect(200)
56+
.end((err, resp) => {
57+
if (err) return done(err)
58+
resp.text.should.match(/^(CON|END) /)
5959
done()
6060
})
6161
})
6262

63-
it('shows menu', function (done) {
63+
it('shows main menu when text is empty', function (done) {
6464
request
6565
.post('/test-service')
6666
.send({ text: '', sessionId: '123', serviceCode: '*123#', phoneNumber: '+1234567890' })
6767
.expect(200)
68-
.end(function (err, resp) {
69-
if (err) throw err
70-
console.log(resp.text + '\n')
71-
const match = resp.text.match('CON ' + menu)
72-
should(match).be.ok()
68+
.end((err, resp) => {
69+
if (err) return done(err)
70+
resp.text.should.equal('CON ' + menu)
7371
done()
7472
})
7573
})
7674

77-
it('shows account info', function (done) {
75+
it('shows account info when user selects option 1', function (done) {
7876
request
7977
.post('/test-service')
8078
.send({ text: '1', sessionId: '123', serviceCode: '*123#', phoneNumber: '+1234567890' })
8179
.expect(200)
82-
.end(function (err, resp) {
83-
if (err) throw err
84-
console.log(resp.text + '\n')
85-
const match = resp.text.match('END ' + accountInfo)
86-
should(match).be.ok()
80+
.end((err, resp) => {
81+
if (err) return done(err)
82+
resp.text.should.equal('END ' + accountInfo)
8783
done()
8884
})
8985
})

0 commit comments

Comments
 (0)