-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Carmichael
committed
Nov 26, 2020
1 parent
6554871
commit 6adaf88
Showing
5 changed files
with
36 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,38 @@ | ||
'use strict'; | ||
|
||
const { expect } = require('@hapi/code'); | ||
const { over } = require('lodash'); | ||
const { omit } = require('lodash'); | ||
const { experiment, test, beforeEach, afterEach } = exports.lab = require('@hapi/lab').script(); | ||
const { experiment, test, beforeEach } = exports.lab = require('@hapi/lab').script(); | ||
|
||
const Joi = require('@hapi/joi').extend( | ||
require('../../src/validators/extensions') | ||
); | ||
|
||
|
||
experiment('validators/extensions.js', () => { | ||
experiment('.convertEmptyStringToNull', () => { | ||
|
||
let schema; | ||
|
||
beforeEach(async () => { | ||
schema = Joi.nullableString(); | ||
}); | ||
|
||
test('converts an empty string to null', async () => { | ||
const { error, value } = Joi.validate('', schema); | ||
const { value } = Joi.validate('', schema); | ||
expect(value).to.be.null(); | ||
}); | ||
|
||
test('converts a padded empty string to null', async () => { | ||
const { error, value } = Joi.validate(' ', schema); | ||
const { value } = Joi.validate(' ', schema); | ||
expect(value).to.be.null(); | ||
}); | ||
|
||
test('leaves other strings unchanged', async () => { | ||
const { error, value } = Joi.validate('Hello', schema); | ||
const { value } = Joi.validate('Hello', schema); | ||
expect(value).to.equal('Hello'); | ||
}); | ||
|
||
test('accepts null', async () => { | ||
const { error, value } = Joi.validate(null, schema); | ||
const { value } = Joi.validate(null, schema); | ||
expect(value).to.be.null(); | ||
}); | ||
|
||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters