Skip to content

Commit

Permalink
✅ Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dtinth committed Sep 4, 2017
1 parent 183c426 commit 75ead17
Show file tree
Hide file tree
Showing 3 changed files with 1,715 additions and 30 deletions.
64 changes: 64 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const generatePayload = require('./')

/* eslint-env jest */
function testcase (name, id, options, expected) {
test(`${name}: ${id} ${require('util').inspect(options)} => ${expected}`, () => {
expect(generatePayload(id, options)).toBe(expected)
})
}

describe('Phone number', () => {
testcase(
'Local phone number',
'0801234567',
{ },
'00020101021129370016A000000677010111011300668012345675802TH530376463046197'
)

testcase(
'Dashed local phone number',
'080-123-4567',
{ },
'00020101021129370016A000000677010111011300668012345675802TH530376463046197'
)

testcase(
'Dashed phone number',
'+66-89-123-4567',
{ },
'00020101021129370016A000000677010111011300668912345675802TH5303764630429C1'
)
})

describe('National ID number', () => {
testcase(
'National ID number',
'1111111111111',
{ },
'00020101021129370016A000000677010111021311111111111115802TH530376463047B5A'
)
testcase(
'Dashed national ID number',
'1-1111-11111-11-1',
{ },
'00020101021129370016A000000677010111021311111111111115802TH530376463047B5A'
)
})

describe('Tax ID', () => {
testcase(
'Tax ID number',
'0123456789012',
{ },
'00020101021129370016A000000677010111021301234567890125802TH530376463040CBD'
)
})

describe('Amount setting', () => {
testcase(
'Amount',
'000-000-0000',
{ amount: 4.22 },
'00020101021229370016A000000677010111011300660000000005802TH530376454044.226304E469'
)
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"cli.js"
],
"devDependencies": {
"jest": "^20.0.4",
"standard": "^10.0.3"
},
"name": "promptpay-qr",
Expand All @@ -19,7 +20,7 @@
"description": "Library to generate PromptPay payload and CLI script to generate QR code",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},
"author": "Thai Pangsakulyanont <[email protected]> (http://dt.in.th/)",
"license": "MIT",
Expand Down
Loading

0 comments on commit 75ead17

Please sign in to comment.