-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(validations): adding validations integration test
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { getRepository, Collection } from '../../src'; | ||
import { Band as BandEntity } from '../fixture'; | ||
import { expect } from 'chai'; | ||
import { getUniqueColName } from '../setup'; | ||
import { IsEmail } from 'class-validator'; | ||
|
||
describe('Integration test: Validations', () => { | ||
@Collection(getUniqueColName('validations')) | ||
class Band extends BandEntity { | ||
@IsEmail() | ||
contactEmail: string; | ||
} | ||
|
||
const bandRepository = getRepository(Band); | ||
|
||
it('should do crud operations with validations', async () => { | ||
// Should create a band when passing a valid email | ||
const dt = new Band(); | ||
dt.id = 'dream-theater'; | ||
dt.name = 'DreamTheater'; | ||
dt.contactEmail = '[email protected]'; | ||
await bandRepository.create(dt); | ||
|
||
const foundBand = await bandRepository.findById(dt.id); | ||
expect(foundBand.id).to.equal(dt.id); | ||
expect(foundBand.contactEmail).to.equal(dt.contactEmail); | ||
|
||
// Should update a band when passing a valid email | ||
dt.contactEmail = '[email protected]'; | ||
await bandRepository.update(dt); | ||
|
||
const updatedDtInDb = await bandRepository.findById(dt.id); | ||
expect(updatedDtInDb.contactEmail).to.equal('[email protected]'); | ||
|
||
// Should throw when trying to create a band with an invalid email | ||
const sw = new Band(); | ||
sw.id = 'steven-wilson'; | ||
sw.name = 'Steven Wilson'; | ||
sw.contactEmail = 'stevenwilson.com'; | ||
|
||
expect(async () => await bandRepository.create(sw)).to.throw; | ||
|
||
// Should throw when trying to update a band with an invalid email | ||
dt.contactEmail = 'dreamtheater.com'; | ||
expect(async () => await bandRepository.update(dt)).to.throw; | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -482,6 +482,18 @@ | |
lodash "^4.17.4" | ||
read-pkg-up "^6.0.0" | ||
|
||
"@types/chai-as-promised@^7.1.2": | ||
version "7.1.2" | ||
resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.2.tgz#2f564420e81eaf8650169e5a3a6b93e096e5068b" | ||
integrity sha512-PO2gcfR3Oxa+u0QvECLe1xKXOqYTzCmWf0FhLhjREoW3fPAVamjihL7v1MOVLJLsnAMdLcjkfrs01yvDMwVK4Q== | ||
dependencies: | ||
"@types/chai" "*" | ||
|
||
"@types/chai@*": | ||
version "4.2.4" | ||
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.2.4.tgz#8936cffad3c96ec470a2dc26a38c3ba8b9b6f619" | ||
integrity sha512-7qvf9F9tMTzo0akeswHPGqgUx/gIaJqrOEET/FCD8CFRkSUHlygQiM5yB6OvjrtdxBVLSyw7COJubsFYs0683g== | ||
|
||
"@types/chai@^4.1.7": | ||
version "4.2.3" | ||
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.2.3.tgz#419477a3d5202bad19e14c787940a61dc9ea6407" | ||
|
@@ -558,6 +570,11 @@ | |
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/[email protected]": | ||
version "10.11.3" | ||
resolved "https://registry.yarnpkg.com/@types/validator/-/validator-10.11.3.tgz#945799bef24a953c5bc02011ca8ad79331a3ef25" | ||
integrity sha512-GKF2VnEkMmEeEGvoo03ocrP9ySMuX1ypKazIYMlsjfslfBMhOAtC5dmEWKdJioW4lJN7MZRS88kalTsVClyQ9w== | ||
|
||
JSONStream@^1.0.4, JSONStream@^1.3.4, JSONStream@^1.3.5: | ||
version "1.3.5" | ||
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0" | ||
|
@@ -1159,6 +1176,13 @@ caseless@~0.12.0: | |
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" | ||
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= | ||
|
||
chai-as-promised@^7.1.1: | ||
version "7.1.1" | ||
resolved "https://registry.yarnpkg.com/chai-as-promised/-/chai-as-promised-7.1.1.tgz#08645d825deb8696ee61725dbf590c012eb00ca0" | ||
integrity sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA== | ||
dependencies: | ||
check-error "^1.0.2" | ||
|
||
chai@^4.2.0: | ||
version "4.2.0" | ||
resolved "https://registry.yarnpkg.com/chai/-/chai-4.2.0.tgz#760aa72cf20e3795e84b12877ce0e83737aa29e5" | ||
|
@@ -1254,6 +1278,15 @@ class-utils@^0.3.5: | |
isobject "^3.0.0" | ||
static-extend "^0.1.1" | ||
|
||
class-validator@^0.10.2: | ||
version "0.10.2" | ||
resolved "https://registry.yarnpkg.com/class-validator/-/class-validator-0.10.2.tgz#361409d7f393df79f602b9a18ebd3e0e51abe320" | ||
integrity sha512-57bGDjoFXizqGZBHe/uHn5/K0MSjBkToaHpDhAXR6DIwjaoET37a0Uug4F5RZR7WF31/7SqzKFIvd+ZspszGUA== | ||
dependencies: | ||
"@types/validator" "10.11.3" | ||
google-libphonenumber "^3.1.6" | ||
validator "11.1.0" | ||
|
||
clean-stack@^2.0.0: | ||
version "2.2.0" | ||
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b" | ||
|
@@ -2901,6 +2934,11 @@ google-gax@^1.6.3: | |
semver "^6.0.0" | ||
walkdir "^0.4.0" | ||
|
||
google-libphonenumber@^3.1.6: | ||
version "3.2.6" | ||
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.6.tgz#3d725b48ff44706b80246e77f95f2c2fdc6fd729" | ||
integrity sha512-6QCQAaKJlSd/1dUqvdQf7zzfb3uiZHsG8yhCfOdCVRfMuPZ/VDIEB47y5SYwjPQJPs7ebfW5jj6PeobB9JJ4JA== | ||
|
||
google-p12-pem@^2.0.0: | ||
version "2.0.2" | ||
resolved "https://registry.yarnpkg.com/google-p12-pem/-/google-p12-pem-2.0.2.tgz#39cae8f6fcbe66a01f00be4ddf2d56b95926fa7b" | ||
|
@@ -7430,6 +7468,11 @@ validate-npm-package-name@^3.0.0, validate-npm-package-name@~3.0.0: | |
dependencies: | ||
builtins "^1.0.3" | ||
|
||
[email protected]: | ||
version "11.1.0" | ||
resolved "https://registry.yarnpkg.com/validator/-/validator-11.1.0.tgz#ac18cac42e0aa5902b603d7a5d9b7827e2346ac4" | ||
integrity sha512-qiQ5ktdO7CD6C/5/mYV4jku/7qnqzjrxb3C/Q5wR3vGGinHTgJZN/TdFT3ZX4vXhX2R1PXx42fB1cn5W+uJ4lg== | ||
|
||
[email protected]: | ||
version "1.10.0" | ||
resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400" | ||
|