Skip to content

Commit e08f31d

Browse files
committed
Add UnitTests for validateDateTime & validateGuid
1 parent 7d9b562 commit e08f31d

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/core/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ export const validateParam = (param, isXml) => {
548548
err = validateGuid(value)
549549
} else {
550550
err = validateString(value)
551-
}
551+
}
552552
if (!err) return errors
553553
errors.push(err)
554554
} else if ( type === "boolean" ) {

test/core/utils.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-env mocha */
22
import expect from "expect"
33
import { fromJS, OrderedMap } from "immutable"
4-
import { mapToList, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered, getAcceptControllingResponse, createDeepLinkPath, escapeDeepLinkPath } from "core/utils"
4+
import { mapToList, validateDateTime, validateGuid, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered, getAcceptControllingResponse, createDeepLinkPath, escapeDeepLinkPath } from "core/utils"
55
import win from "core/window"
66

77
describe("utils", function() {
@@ -158,7 +158,7 @@ describe("utils", function() {
158158
})
159159
})
160160

161-
describe("validateFile", function() {
161+
describe("validateFile", function() {
162162
let errorMessage = "Value must be a file"
163163

164164
it("validates against objects which are instances of 'File'", function() {
@@ -171,6 +171,34 @@ describe("utils", function() {
171171
})
172172
})
173173

174+
describe("validateDateTime", function() {
175+
let errorMessage = "Value must be a DateTime"
176+
177+
it("doesn't return for valid dates", function() {
178+
expect(validateFile(fileObj)).toBeFalsy()
179+
expect(validateFile(null)).toBeFalsy()
180+
})
181+
182+
it("returns a message for invalid input'", function() {
183+
expect(validateFile(1)).toEqual(errorMessage)
184+
expect(validateFile("string")).toEqual(errorMessage)
185+
})
186+
})
187+
188+
describe("validateGuid", function() {
189+
let errorMessage = "Value must be a Guid"
190+
191+
it("doesn't return for valid guid", function() {
192+
expect(validateGuid("8ce4811e-cec5-4a29-891a-15d1917153c1")).toBeFalsy()
193+
expect(validateGuid("{8ce4811e-cec5-4a29-891a-15d1917153c1}")).toBeFalsy()
194+
})
195+
196+
it("returns a message for invalid input'", function() {
197+
expect(validateGuid(1)).toEqual(errorMessage)
198+
expect(validateGuid("string")).toEqual(errorMessage)
199+
})
200+
})
201+
174202
describe("validateParam", function() {
175203
let param = null
176204
let result = null

0 commit comments

Comments
 (0)