-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some integration tests for the Cat API
- Loading branch information
Jonas Verhoelen
committed
May 1, 2019
1 parent
a49292a
commit 0bfdf5c
Showing
5 changed files
with
250 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,71 @@ | ||
import * as request from 'supertest' | ||
import { expect } from 'chai' | ||
import * as HttpStatus from 'http-status-codes' | ||
import TestEnv from './TestEnv' | ||
|
||
const { baseUrl } = TestEnv | ||
|
||
describe('Cats API', () => { | ||
describe('Cat details', () => { | ||
it('should respond with a positive status code if the cat is known', () => { | ||
return request(baseUrl) | ||
.get('/api/cat/1') | ||
.expect(HttpStatus.OK) | ||
}) | ||
|
||
it('should respond with 404 status code if the cat is not known', () => { | ||
return request(baseUrl) | ||
.get('/api/cat/666') | ||
.expect(HttpStatus.NOT_FOUND) | ||
}) | ||
|
||
it('should respond with cat details data if the cat is known', () => { | ||
return request(baseUrl) | ||
.get('/api/cat/1') | ||
.expect((res: Response) => { | ||
expect(res.body).to.deep.equal({ | ||
id: 1, | ||
name: 'Tony Iommi', | ||
breed: 'British Shorthair', | ||
gender: 'male', | ||
age: 71 | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('All cats', () => { | ||
it('should respond with a positive status code', () => { | ||
return request(baseUrl) | ||
.get('/api/cat') | ||
.expect(HttpStatus.OK) | ||
}) | ||
|
||
it('should return a reasonable amount of cats entries', () => { | ||
return request(baseUrl) | ||
.get('/api/cat') | ||
.expect((res: Response) => { | ||
expect((res.body as any).length).to.eq(5) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('Cat statistics', () => { | ||
it('should respond with a positive status code', () => { | ||
return request(baseUrl) | ||
.get('/api/statistics/cat') | ||
.expect(HttpStatus.OK) | ||
}) | ||
|
||
it('should deliver a reasonable statistics response', () => { | ||
return request(baseUrl) | ||
.get('/api/statistics/cat') | ||
.expect((res: Response) => { | ||
expect(res.body).to.deep.eq({ | ||
amount: 5, | ||
averageAge: 69.2 | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
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,4 @@ | ||
export default class TestEnv { | ||
public static readonly local = !process.env.BASE_URL | ||
public static readonly baseUrl = process.env.BASE_URL || 'http://localhost:8000' | ||
} |