Skip to content

Commit

Permalink
feat(rxjs): rxjs-sample added with a generic retry strategy
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jmcdo29 authored Nov 29, 2019
1 parent c771957 commit 1a5f4a5
Show file tree
Hide file tree
Showing 36 changed files with 643 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
node-version: [10.x, 12.x]
app-name: [simple-sample, complex-sample, mongo-sample, typeorm-sample, typeorm-graphql-sample, websocket-sample]
app-name: [simple-sample, complex-sample, mongo-sample, typeorm-sample, typeorm-graphql-sample, websocket-sample, rxjs-sample]

steps:
- uses: actions/checkout@v1
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/rxjs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: RxJS Sample

on:
pull_request:
branches:
- 'master'
push:
branches:
- 'rxjs'

jobs:
test:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install
run: npm ci
- name: npm test
run: npm test -- rxjs-sample
env:
CI: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div align="center">

[![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/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)

</div>

Expand Down
15 changes: 9 additions & 6 deletions apps/complex-sample/src/cat/cat.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { CatController } from './cat.controller';
import { CatService } from './cat.service';
import { Cat } from './models/cats';

const testCat1 = 'Test Cat 1';
const testCat3 = 'Test Cat 3';

describe('Cat Controller', () => {
let controller: CatController;

Expand All @@ -24,15 +27,15 @@ describe('Cat Controller', () => {
getAll: jest
.fn()
.mockReturnValue([
new Cat(1, 'Test Cat 1', 'Test Breed 1', 2),
new Cat(1, testCat1, 'Test Breed 1', 2),
new Cat(2, 'Test Cat 2', 'Test Breed 2', 4),
]),
getById: jest
.fn()
.mockReturnValue(new Cat(1, 'Test Cat 1', 'Test Breed 1', 2)),
.mockReturnValue(new Cat(1, testCat1, 'Test Breed 1', 2)),
addCat: jest
.fn()
.mockReturnValue(new Cat(3, 'Test Cat 3', 'Test Breed 3', 5)),
.mockReturnValue(new Cat(3, testCat3, 'Test Breed 3', 5)),
deleteCat: jest.fn().mockReturnValue(true),
},
},
Expand Down Expand Up @@ -64,18 +67,18 @@ describe('Cat Controller', () => {
const retCat = controller.getCatById(1);
expect(typeof retCat).toBe('object');
expect(retCat.id).toBe(1);
expect(retCat.name).toBe('Test Cat 1');
expect(retCat.name).toBe(testCat1);
});
});
describe('createNewCat', () => {
it('should return a new cat', () => {
const returnedCat = controller.createNewCat({
age: 5,
name: 'Test Cat 3',
name: testCat3,
breed: 'Test Breed 3',
});
expect(returnedCat.id).toBe(3);
expect(returnedCat.name).toBe('Test Cat 3');
expect(returnedCat.name).toBe(testCat3);
});
});
describe('deleteCat', () => {
Expand Down
27 changes: 15 additions & 12 deletions apps/complex-sample/src/cat/cat.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { CatPipe } from './cat.pipe';
import { CatDTO } from './dto/cats.dto';

const metadata = {} as any;
const testBreed = 'Test Breed';
const badRequest = 'Bad Request';
const failString = 'should throw an error for incorrect type';

describe('CatPipe', () => {
let pipe: CatPipe;
Expand All @@ -14,7 +17,7 @@ describe('CatPipe', () => {
});
describe('successful calls', () => {
it('should let the cat DTO go on through', () => {
const catDTO = { name: 'Test Name', breed: 'Test Breed', age: 4 };
const catDTO = { name: 'Test Name', breed: testBreed, age: 4 };
expect(pipe.transform(catDTO, metadata)).toEqual(catDTO);
});
});
Expand All @@ -28,7 +31,7 @@ describe('CatPipe', () => {
describe('age errors', () => {
const badAgeCat: CatDTO = {
name: 'Test Name',
breed: 'Test Breed',
breed: testBreed,
} as any;
it('should throw an error for missing age', () => {
try {
Expand All @@ -38,10 +41,10 @@ describe('CatPipe', () => {
'Incoming cat is not formated correctly. Age must be a number.',
);
expect(err.message.statusCode).toBe(400);
expect(err.message.error).toBe('Bad Request');
expect(err.message.error).toBe(badRequest);
}
});
it('should throw an error for incorrect type', () => {
it(failString, () => {
try {
badAgeCat.age = '5' as any;
pipe.transform(badAgeCat, metadata);
Expand All @@ -50,14 +53,14 @@ describe('CatPipe', () => {
'Incoming cat is not formated correctly. Age must be a number.',
);
expect(err.message.statusCode).toBe(400);
expect(err.message.error).toBe('Bad Request');
expect(err.message.error).toBe(badRequest);
}
});
});
describe('name errors', () => {
const badNameCat: CatDTO = {
age: 5,
breed: 'Test Breed',
breed: testBreed,
} as any;
it('should throw an error for missing name', () => {
try {
Expand All @@ -67,10 +70,10 @@ describe('CatPipe', () => {
'Incoming cat is not formated correctly. Name must be a string.',
);
expect(err.message.statusCode).toBe(400);
expect(err.message.error).toBe('Bad Request');
expect(err.message.error).toBe(badRequest);
}
});
it('should throw an error for incorrect type', () => {
it(failString, () => {
try {
badNameCat.name = true as any;
pipe.transform(badNameCat as any, metadata);
Expand All @@ -79,7 +82,7 @@ describe('CatPipe', () => {
'Incoming cat is not formated correctly. Name must be a string.',
);
expect(err.message.statusCode).toBe(400);
expect(err.message.error).toBe('Bad Request');
expect(err.message.error).toBe(badRequest);
}
});
});
Expand All @@ -96,10 +99,10 @@ describe('CatPipe', () => {
'Incoming cat is not formated correctly. Breed must be a string.',
);
expect(err.message.statusCode).toBe(400);
expect(err.message.error).toBe('Bad Request');
expect(err.message.error).toBe(badRequest);
}
});
it('should throw an error for incorrect type', () => {
it(failString, () => {
try {
badBreedCat.breed = true as any;
pipe.transform(badBreedCat as any, metadata);
Expand All @@ -108,7 +111,7 @@ describe('CatPipe', () => {
'Incoming cat is not formated correctly. Breed must be a string.',
);
expect(err.message.statusCode).toBe(400);
expect(err.message.error).toBe('Bad Request');
expect(err.message.error).toBe(badRequest);
}
});
});
Expand Down
15 changes: 9 additions & 6 deletions apps/complex-sample/src/cat/cat.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Test, TestingModule } from '@nestjs/testing';
import { CatService } from './cat.service';
import { CatDTO } from './dto/cats.dto';

const testCat1 = 'Test Cat 1';
const testBreed1 = 'Test Breed 1';

describe('CatService', () => {
let service: CatService;

Expand Down Expand Up @@ -49,8 +52,8 @@ describe('CatService', () => {
describe('addCat', () => {
it('should add the cat', () => {
const catDTO: CatDTO = {
name: 'Test Cat 1',
breed: 'Test Breed 1',
name: testCat1,
breed: testBreed1,
age: 8,
};
const newCat = service.addCat(catDTO);
Expand All @@ -77,14 +80,14 @@ describe('CatService', () => {
const firstCatSetLength = firstCatSet.length;
expect(firstCatSet.length).toBe(3);
const newCat = service.addCat({
name: 'Test Cat 1',
breed: 'Test Breed 1',
name: testCat1,
breed: testBreed1,
age: 4,
});
expect(newCat).toEqual({
id: 4,
name: 'Test Cat 1',
breed: 'Test Breed 1',
name: testCat1,
breed: testBreed1,
age: 4,
});
const secondCatSet = service.getAll();
Expand Down
Loading

0 comments on commit 1a5f4a5

Please sign in to comment.