Skip to content

Commit

Permalink
chore: simplify test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Raymond Feng <[email protected]>
  • Loading branch information
raymondfeng committed Sep 25, 2018
1 parent f0c76eb commit 366433c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 33 deletions.
14 changes: 3 additions & 11 deletions test/acceptance/ping.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {createClientForHandler, supertest, expect} from '@loopback/testlab';
import {RestServer} from '@loopback/rest';
import {createRestAppClient, Client, expect} from '@loopback/testlab';
import {ShoppingApplication} from '../..';

describe('PingController', () => {
let app: ShoppingApplication;
let server: RestServer;
let client: supertest.SuperTest<supertest.Test>;
let client: Client;

before(givenAnApplication);

before(givenARestServer);

before(async () => {
await app.boot();
await app.start();
});

before(() => {
client = createClientForHandler(server.requestHandler);
client = createRestAppClient(app);
});

after(async () => {
Expand All @@ -41,8 +37,4 @@ describe('PingController', () => {
},
});
}

async function givenARestServer() {
server = await app.getServer(RestServer);
}
});
14 changes: 3 additions & 11 deletions test/acceptance/shopping-cart.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,26 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {createClientForHandler, supertest, expect} from '@loopback/testlab';
import {RestServer} from '@loopback/rest';
import {createRestAppClient, Client, expect} from '@loopback/testlab';
import {ShoppingApplication} from '../..';
import {ShoppingCartRepository} from '../../src/repositories';
import {RedisDataSource} from '../../src/datasources';
import {ShoppingCart, ShoppingCartItem} from '../../src/models';

describe('ShoppingCartController', () => {
let app: ShoppingApplication;
let server: RestServer;
let client: supertest.SuperTest<supertest.Test>;
let client: Client;
const cartRepo = new ShoppingCartRepository(new RedisDataSource());

before(givenAnApplication);

before(givenARestServer);

before(async () => {
await app.boot();
await app.start();
});

before(() => {
client = createClientForHandler(server.requestHandler);
client = createRestAppClient(app);
});

beforeEach(clearDatabase);
Expand Down Expand Up @@ -109,10 +105,6 @@ describe('ShoppingCartController', () => {
});
}

async function givenARestServer() {
server = await app.getServer(RestServer);
}

async function clearDatabase() {
await cartRepo.deleteAll();
}
Expand Down
14 changes: 3 additions & 11 deletions test/acceptance/user.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {createClientForHandler, supertest, expect} from '@loopback/testlab';
import {RestServer} from '@loopback/rest';
import {createRestAppClient, Client, expect} from '@loopback/testlab';
import {ShoppingApplication} from '../..';
import {UserRepository} from '../../src/repositories';
import {UserDataSource} from '../../src/datasources';

describe('UserController', () => {
let app: ShoppingApplication;
let server: RestServer;
let client: supertest.SuperTest<supertest.Test>;
let client: Client;
const userRepo = new UserRepository(new UserDataSource());

const user = {
Expand All @@ -24,15 +22,13 @@ describe('UserController', () => {

before(givenAnApplication);

before(givenARestServer);

before(async () => {
await app.boot();
await app.start();
});

before(() => {
client = createClientForHandler(server.requestHandler);
client = createRestAppClient(app);
});

beforeEach(clearDatabase);
Expand Down Expand Up @@ -124,10 +120,6 @@ describe('UserController', () => {
});
}

async function givenARestServer() {
server = await app.getServer(RestServer);
}

async function clearDatabase() {
await userRepo.deleteAll();
}
Expand Down

0 comments on commit 366433c

Please sign in to comment.