Skip to content

Commit 1a5f4a5

Browse files
authored
feat(rxjs): rxjs-sample added with a generic retry strategy
* feat(rxjs): initial implementation of rxjs sample re #16 * feat(rxjs): finished implementation of rxjs sample with 100% coverage RxJS sample now has 100% coverage. Also added sonarts lint rules fix #16
1 parent c771957 commit 1a5f4a5

36 files changed

+643
-122
lines changed

.github/workflows/cron.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
node-version: [10.x, 12.x]
15-
app-name: [simple-sample, complex-sample, mongo-sample, typeorm-sample, typeorm-graphql-sample, websocket-sample]
15+
app-name: [simple-sample, complex-sample, mongo-sample, typeorm-sample, typeorm-graphql-sample, websocket-sample, rxjs-sample]
1616

1717
steps:
1818
- uses: actions/checkout@v1

.github/workflows/rxjs.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: RxJS Sample
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 'master'
7+
push:
8+
branches:
9+
- 'rxjs'
10+
11+
jobs:
12+
test:
13+
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [10.x, 12.x]
19+
20+
steps:
21+
- uses: actions/checkout@v1
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- name: npm install
27+
run: npm ci
28+
- name: npm test
29+
run: npm test -- rxjs-sample
30+
env:
31+
CI: true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<div align="center">
44

5-
[![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/CRON%20Job/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/Complex%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/Simple%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/Mongo%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/TypeORM%20GraphQL%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/TypeORM%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/WebSocket%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions)
5+
[![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/CRON%20Job/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/Complex%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/Simple%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/Mongo%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/TypeORM%20GraphQL%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/TypeORM%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions) [![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/WebSocket%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions)[![Actions Status](https://github.com/jmcdo29/testing-nestjs/workflows/RxJS%20Sample/badge.svg)](https://github.com/jmcdo29/testing-nestjs/actions)
66

77
</div>
88

apps/complex-sample/src/cat/cat.controller.spec.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { CatController } from './cat.controller';
33
import { CatService } from './cat.service';
44
import { Cat } from './models/cats';
55

6+
const testCat1 = 'Test Cat 1';
7+
const testCat3 = 'Test Cat 3';
8+
69
describe('Cat Controller', () => {
710
let controller: CatController;
811

@@ -24,15 +27,15 @@ describe('Cat Controller', () => {
2427
getAll: jest
2528
.fn()
2629
.mockReturnValue([
27-
new Cat(1, 'Test Cat 1', 'Test Breed 1', 2),
30+
new Cat(1, testCat1, 'Test Breed 1', 2),
2831
new Cat(2, 'Test Cat 2', 'Test Breed 2', 4),
2932
]),
3033
getById: jest
3134
.fn()
32-
.mockReturnValue(new Cat(1, 'Test Cat 1', 'Test Breed 1', 2)),
35+
.mockReturnValue(new Cat(1, testCat1, 'Test Breed 1', 2)),
3336
addCat: jest
3437
.fn()
35-
.mockReturnValue(new Cat(3, 'Test Cat 3', 'Test Breed 3', 5)),
38+
.mockReturnValue(new Cat(3, testCat3, 'Test Breed 3', 5)),
3639
deleteCat: jest.fn().mockReturnValue(true),
3740
},
3841
},
@@ -64,18 +67,18 @@ describe('Cat Controller', () => {
6467
const retCat = controller.getCatById(1);
6568
expect(typeof retCat).toBe('object');
6669
expect(retCat.id).toBe(1);
67-
expect(retCat.name).toBe('Test Cat 1');
70+
expect(retCat.name).toBe(testCat1);
6871
});
6972
});
7073
describe('createNewCat', () => {
7174
it('should return a new cat', () => {
7275
const returnedCat = controller.createNewCat({
7376
age: 5,
74-
name: 'Test Cat 3',
77+
name: testCat3,
7578
breed: 'Test Breed 3',
7679
});
7780
expect(returnedCat.id).toBe(3);
78-
expect(returnedCat.name).toBe('Test Cat 3');
81+
expect(returnedCat.name).toBe(testCat3);
7982
});
8083
});
8184
describe('deleteCat', () => {

apps/complex-sample/src/cat/cat.pipe.spec.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { CatPipe } from './cat.pipe';
22
import { CatDTO } from './dto/cats.dto';
33

44
const metadata = {} as any;
5+
const testBreed = 'Test Breed';
6+
const badRequest = 'Bad Request';
7+
const failString = 'should throw an error for incorrect type';
58

69
describe('CatPipe', () => {
710
let pipe: CatPipe;
@@ -14,7 +17,7 @@ describe('CatPipe', () => {
1417
});
1518
describe('successful calls', () => {
1619
it('should let the cat DTO go on through', () => {
17-
const catDTO = { name: 'Test Name', breed: 'Test Breed', age: 4 };
20+
const catDTO = { name: 'Test Name', breed: testBreed, age: 4 };
1821
expect(pipe.transform(catDTO, metadata)).toEqual(catDTO);
1922
});
2023
});
@@ -28,7 +31,7 @@ describe('CatPipe', () => {
2831
describe('age errors', () => {
2932
const badAgeCat: CatDTO = {
3033
name: 'Test Name',
31-
breed: 'Test Breed',
34+
breed: testBreed,
3235
} as any;
3336
it('should throw an error for missing age', () => {
3437
try {
@@ -38,10 +41,10 @@ describe('CatPipe', () => {
3841
'Incoming cat is not formated correctly. Age must be a number.',
3942
);
4043
expect(err.message.statusCode).toBe(400);
41-
expect(err.message.error).toBe('Bad Request');
44+
expect(err.message.error).toBe(badRequest);
4245
}
4346
});
44-
it('should throw an error for incorrect type', () => {
47+
it(failString, () => {
4548
try {
4649
badAgeCat.age = '5' as any;
4750
pipe.transform(badAgeCat, metadata);
@@ -50,14 +53,14 @@ describe('CatPipe', () => {
5053
'Incoming cat is not formated correctly. Age must be a number.',
5154
);
5255
expect(err.message.statusCode).toBe(400);
53-
expect(err.message.error).toBe('Bad Request');
56+
expect(err.message.error).toBe(badRequest);
5457
}
5558
});
5659
});
5760
describe('name errors', () => {
5861
const badNameCat: CatDTO = {
5962
age: 5,
60-
breed: 'Test Breed',
63+
breed: testBreed,
6164
} as any;
6265
it('should throw an error for missing name', () => {
6366
try {
@@ -67,10 +70,10 @@ describe('CatPipe', () => {
6770
'Incoming cat is not formated correctly. Name must be a string.',
6871
);
6972
expect(err.message.statusCode).toBe(400);
70-
expect(err.message.error).toBe('Bad Request');
73+
expect(err.message.error).toBe(badRequest);
7174
}
7275
});
73-
it('should throw an error for incorrect type', () => {
76+
it(failString, () => {
7477
try {
7578
badNameCat.name = true as any;
7679
pipe.transform(badNameCat as any, metadata);
@@ -79,7 +82,7 @@ describe('CatPipe', () => {
7982
'Incoming cat is not formated correctly. Name must be a string.',
8083
);
8184
expect(err.message.statusCode).toBe(400);
82-
expect(err.message.error).toBe('Bad Request');
85+
expect(err.message.error).toBe(badRequest);
8386
}
8487
});
8588
});
@@ -96,10 +99,10 @@ describe('CatPipe', () => {
9699
'Incoming cat is not formated correctly. Breed must be a string.',
97100
);
98101
expect(err.message.statusCode).toBe(400);
99-
expect(err.message.error).toBe('Bad Request');
102+
expect(err.message.error).toBe(badRequest);
100103
}
101104
});
102-
it('should throw an error for incorrect type', () => {
105+
it(failString, () => {
103106
try {
104107
badBreedCat.breed = true as any;
105108
pipe.transform(badBreedCat as any, metadata);
@@ -108,7 +111,7 @@ describe('CatPipe', () => {
108111
'Incoming cat is not formated correctly. Breed must be a string.',
109112
);
110113
expect(err.message.statusCode).toBe(400);
111-
expect(err.message.error).toBe('Bad Request');
114+
expect(err.message.error).toBe(badRequest);
112115
}
113116
});
114117
});

apps/complex-sample/src/cat/cat.service.spec.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Test, TestingModule } from '@nestjs/testing';
22
import { CatService } from './cat.service';
33
import { CatDTO } from './dto/cats.dto';
44

5+
const testCat1 = 'Test Cat 1';
6+
const testBreed1 = 'Test Breed 1';
7+
58
describe('CatService', () => {
69
let service: CatService;
710

@@ -49,8 +52,8 @@ describe('CatService', () => {
4952
describe('addCat', () => {
5053
it('should add the cat', () => {
5154
const catDTO: CatDTO = {
52-
name: 'Test Cat 1',
53-
breed: 'Test Breed 1',
55+
name: testCat1,
56+
breed: testBreed1,
5457
age: 8,
5558
};
5659
const newCat = service.addCat(catDTO);
@@ -77,14 +80,14 @@ describe('CatService', () => {
7780
const firstCatSetLength = firstCatSet.length;
7881
expect(firstCatSet.length).toBe(3);
7982
const newCat = service.addCat({
80-
name: 'Test Cat 1',
81-
breed: 'Test Breed 1',
83+
name: testCat1,
84+
breed: testBreed1,
8285
age: 4,
8386
});
8487
expect(newCat).toEqual({
8588
id: 4,
86-
name: 'Test Cat 1',
87-
breed: 'Test Breed 1',
89+
name: testCat1,
90+
breed: testBreed1,
8891
age: 4,
8992
});
9093
const secondCatSet = service.getAll();

0 commit comments

Comments
 (0)