-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest.js
More file actions
47 lines (36 loc) · 1.06 KB
/
Copy pathtest.js
File metadata and controls
47 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const test = require('ava');
const Joi = require('joi')
.extend(require('./src/joi-currency-code'));
const schema = Joi.object({
code: Joi.string().currency(),
});
test('should succeed if currency code is valid - lowercase', t => {
const output = schema.validate({
code: 'aud',
});
t.deepEqual(output.value, {code: 'AUD'});
});
test('should succeed if currency code is valid - uppercase', t => {
const output = schema.validate({
code: 'AUD',
});
t.deepEqual(output.value, {code: 'AUD'});
});
test('should fail if currency code is invalid', t => {
const {error: {message}} = schema.validate({
code: 'fake-currency',
});
t.is(message, '"code" must be a valid ISO 4217 currency code');
});
test('should fail if currency code type is boolean', t => {
const {error: {message}} = schema.validate({
code: 123,
});
t.is(message, '"code" must be a string');
});
test('should fail if currency code type is object', t => {
const {error: {message}} = schema.validate({
code: {},
});
t.is(message, '"code" must be a string');
});