Skip to content

Commit 65306d3

Browse files
committed
test: for validateB64(), validateB64URL()
1 parent 5863162 commit 65306d3

1 file changed

Lines changed: 73 additions & 20 deletions

File tree

test/30_helper.test.ts

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
parseTextEncoder,
2222
testB64,
2323
testB64URL,
24+
validateB64,
25+
validateB64URL,
2426
validateEncoder,
2527
validB64Chars,
2628
validB64URLChars,
@@ -201,60 +203,93 @@ describe(filename, () => {
201203
})
202204

203205

204-
describe('validBase64Chars() works', () => {
206+
describe('validateB64() works', () => {
205207
it('with valid input', () => {
206208
['QQ=='].forEach(b64 => {
207-
const ret = validB64Chars(b64)
208-
assert(ret === true, b64.toString())
209+
validateB64(b64)
209210
})
210211
})
211212

212213
it('with invalid input', () => {
213-
const arr = inputBase64CharsInvalid
214-
arr.forEach((b64, idx) => {
215-
const ret = validB64Chars(<any> b64)
216-
assert(ret === false, `${ b64.toString()} : idx`)
214+
const arr = [
215+
...inputBase64CharsInvalid,
216+
...inputBase64Invalid,
217+
]
218+
arr.forEach(b64 => {
219+
try {
220+
validateB64(<any> b64)
221+
assert(false, 'Should throw error, but NOT')
222+
}
223+
catch (ex) {
224+
assert(true)
225+
}
217226
})
218227
})
219228
})
220229

221230

222-
describe('validBase64URLChars() works', () => {
231+
describe('testBase64() works', () => {
223232
it('with valid input', () => {
224-
['Q'].forEach(b64 => {
225-
const ret = validB64URLChars(b64)
233+
['QQ=='].forEach(b64 => {
234+
const ret = testB64(b64)
226235
assert(ret === true)
227236
})
228237
})
229238

230239
it('with invalid input', () => {
231-
const arr = inputBase64URLCharsInvalid
240+
const arr = [
241+
...inputBase64CharsInvalid,
242+
...inputBase64Invalid,
243+
]
232244
arr.forEach(b64 => {
233-
const ret = validB64URLChars(b64)
234-
assert(ret === false, b64)
245+
const ret = testB64(<any> b64)
246+
assert(ret !== true, b64.toString())
235247
})
248+
236249
})
237250
})
238251

239252

240-
describe('testBase64() works', () => {
253+
describe('validBase64Chars() works', () => {
241254
it('with valid input', () => {
242255
['QQ=='].forEach(b64 => {
243-
const ret = testB64(b64)
244-
assert(ret === true)
256+
const ret = validB64Chars(b64)
257+
assert(ret === true, b64.toString())
258+
})
259+
})
260+
261+
it('with invalid input', () => {
262+
const arr = inputBase64CharsInvalid
263+
arr.forEach((b64, idx) => {
264+
const ret = validB64Chars(<any> b64)
265+
assert(ret === false, `${ b64.toString()} : idx`)
266+
})
267+
})
268+
})
269+
270+
271+
describe('validateB64URL() works', () => {
272+
it('with valid input', () => {
273+
['QQ'].forEach(b64 => {
274+
validateB64URL(b64)
245275
})
246276
})
247277

248278
it('with invalid input', () => {
249279
const arr = [
280+
...inputBase64URLCharsInvalid,
250281
...inputBase64CharsInvalid,
251-
...inputBase64Invalid,
282+
...inputBase64URLInvalid,
252283
]
253284
arr.forEach(b64 => {
254-
const ret = testB64(<any> b64)
255-
assert(ret !== true, b64.toString())
285+
try {
286+
validateB64URL(<any> b64)
287+
assert(false, 'Should throw error, but NOT')
288+
}
289+
catch (ex) {
290+
assert(true)
291+
}
256292
})
257-
258293
})
259294
})
260295

@@ -281,4 +316,22 @@ describe(filename, () => {
281316
})
282317

283318

319+
describe('validBase64URLChars() works', () => {
320+
it('with valid input', () => {
321+
['Q'].forEach(b64 => {
322+
const ret = validB64URLChars(b64)
323+
assert(ret === true)
324+
})
325+
})
326+
327+
it('with invalid input', () => {
328+
const arr = inputBase64URLCharsInvalid
329+
arr.forEach(b64 => {
330+
const ret = validB64URLChars(b64)
331+
assert(ret === false, b64)
332+
})
333+
})
334+
})
335+
336+
284337
})

0 commit comments

Comments
 (0)