Skip to content

Commit bc108bb

Browse files
committed
test(validations): adding validations integration test
1 parent b25f6d0 commit bc108bb

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { getRepository, Collection } from '../../src';
2+
import { Band as BandEntity } from '../fixture';
3+
import { expect } from 'chai';
4+
import { getUniqueColName } from '../setup';
5+
import { IsEmail } from 'class-validator';
6+
7+
describe('Integration test: Validations', () => {
8+
@Collection(getUniqueColName('validations'))
9+
class Band extends BandEntity {
10+
@IsEmail()
11+
contactEmail: string;
12+
}
13+
14+
const bandRepository = getRepository(Band);
15+
16+
it('should do crud operations with validations', async () => {
17+
// Should create a band when passing a valid email
18+
const dt = new Band();
19+
dt.id = 'dream-theater';
20+
dt.name = 'DreamTheater';
21+
dt.contactEmail = '[email protected]';
22+
await bandRepository.create(dt);
23+
24+
const foundBand = await bandRepository.findById(dt.id);
25+
expect(foundBand.id).to.equal(dt.id);
26+
expect(foundBand.contactEmail).to.equal(dt.contactEmail);
27+
28+
// Should update a band when passing a valid email
29+
dt.contactEmail = '[email protected]';
30+
await bandRepository.update(dt);
31+
32+
const updatedDtInDb = await bandRepository.findById(dt.id);
33+
expect(updatedDtInDb.contactEmail).to.equal('[email protected]');
34+
35+
// Should throw when trying to create a band with an invalid email
36+
const sw = new Band();
37+
sw.id = 'steven-wilson';
38+
sw.name = 'Steven Wilson';
39+
sw.contactEmail = 'stevenwilson.com';
40+
41+
expect(async () => await bandRepository.create(sw)).to.throw;
42+
43+
// Should throw when trying to update a band with an invalid email
44+
dt.contactEmail = 'dreamtheater.com';
45+
expect(async () => await bandRepository.update(dt)).to.throw;
46+
});
47+
});

yarn.lock

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,18 @@
482482
lodash "^4.17.4"
483483
read-pkg-up "^6.0.0"
484484

485+
"@types/chai-as-promised@^7.1.2":
486+
version "7.1.2"
487+
resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.2.tgz#2f564420e81eaf8650169e5a3a6b93e096e5068b"
488+
integrity sha512-PO2gcfR3Oxa+u0QvECLe1xKXOqYTzCmWf0FhLhjREoW3fPAVamjihL7v1MOVLJLsnAMdLcjkfrs01yvDMwVK4Q==
489+
dependencies:
490+
"@types/chai" "*"
491+
492+
"@types/chai@*":
493+
version "4.2.4"
494+
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.2.4.tgz#8936cffad3c96ec470a2dc26a38c3ba8b9b6f619"
495+
integrity sha512-7qvf9F9tMTzo0akeswHPGqgUx/gIaJqrOEET/FCD8CFRkSUHlygQiM5yB6OvjrtdxBVLSyw7COJubsFYs0683g==
496+
485497
"@types/chai@^4.1.7":
486498
version "4.2.3"
487499
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.2.3.tgz#419477a3d5202bad19e14c787940a61dc9ea6407"
@@ -558,6 +570,11 @@
558570
dependencies:
559571
"@types/node" "*"
560572

573+
574+
version "10.11.3"
575+
resolved "https://registry.yarnpkg.com/@types/validator/-/validator-10.11.3.tgz#945799bef24a953c5bc02011ca8ad79331a3ef25"
576+
integrity sha512-GKF2VnEkMmEeEGvoo03ocrP9ySMuX1ypKazIYMlsjfslfBMhOAtC5dmEWKdJioW4lJN7MZRS88kalTsVClyQ9w==
577+
561578
JSONStream@^1.0.4, JSONStream@^1.3.4, JSONStream@^1.3.5:
562579
version "1.3.5"
563580
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
@@ -1159,6 +1176,13 @@ caseless@~0.12.0:
11591176
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
11601177
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=
11611178

1179+
chai-as-promised@^7.1.1:
1180+
version "7.1.1"
1181+
resolved "https://registry.yarnpkg.com/chai-as-promised/-/chai-as-promised-7.1.1.tgz#08645d825deb8696ee61725dbf590c012eb00ca0"
1182+
integrity sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==
1183+
dependencies:
1184+
check-error "^1.0.2"
1185+
11621186
chai@^4.2.0:
11631187
version "4.2.0"
11641188
resolved "https://registry.yarnpkg.com/chai/-/chai-4.2.0.tgz#760aa72cf20e3795e84b12877ce0e83737aa29e5"
@@ -1254,6 +1278,15 @@ class-utils@^0.3.5:
12541278
isobject "^3.0.0"
12551279
static-extend "^0.1.1"
12561280

1281+
class-validator@^0.10.2:
1282+
version "0.10.2"
1283+
resolved "https://registry.yarnpkg.com/class-validator/-/class-validator-0.10.2.tgz#361409d7f393df79f602b9a18ebd3e0e51abe320"
1284+
integrity sha512-57bGDjoFXizqGZBHe/uHn5/K0MSjBkToaHpDhAXR6DIwjaoET37a0Uug4F5RZR7WF31/7SqzKFIvd+ZspszGUA==
1285+
dependencies:
1286+
"@types/validator" "10.11.3"
1287+
google-libphonenumber "^3.1.6"
1288+
validator "11.1.0"
1289+
12571290
clean-stack@^2.0.0:
12581291
version "2.2.0"
12591292
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
@@ -2901,6 +2934,11 @@ google-gax@^1.6.3:
29012934
semver "^6.0.0"
29022935
walkdir "^0.4.0"
29032936

2937+
google-libphonenumber@^3.1.6:
2938+
version "3.2.6"
2939+
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.6.tgz#3d725b48ff44706b80246e77f95f2c2fdc6fd729"
2940+
integrity sha512-6QCQAaKJlSd/1dUqvdQf7zzfb3uiZHsG8yhCfOdCVRfMuPZ/VDIEB47y5SYwjPQJPs7ebfW5jj6PeobB9JJ4JA==
2941+
29042942
google-p12-pem@^2.0.0:
29052943
version "2.0.2"
29062944
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:
74307468
dependencies:
74317469
builtins "^1.0.3"
74327470

7471+
7472+
version "11.1.0"
7473+
resolved "https://registry.yarnpkg.com/validator/-/validator-11.1.0.tgz#ac18cac42e0aa5902b603d7a5d9b7827e2346ac4"
7474+
integrity sha512-qiQ5ktdO7CD6C/5/mYV4jku/7qnqzjrxb3C/Q5wR3vGGinHTgJZN/TdFT3ZX4vXhX2R1PXx42fB1cn5W+uJ4lg==
7475+
74337476
74347477
version "1.10.0"
74357478
resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400"

0 commit comments

Comments
 (0)