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 2c90810 commit 293177b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
12 changes: 10 additions & 2 deletions test/acceptance/home-page.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

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

describe('HomePageController', () => {
let app: ShoppingApplication;
let server: RestServer;
let client: Client;

before(givenAnApplication);

before(givenARestServer);

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

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

after(async () => {
Expand All @@ -40,4 +44,8 @@ describe('HomePageController', () => {
},
});
}

async function givenARestServer() {
server = await app.getServer(RestServer);
}
});
4 changes: 2 additions & 2 deletions test/acceptance/ping.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +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 {createClientForHandler, Client, expect} from '@loopback/testlab';
import {RestServer} from '@loopback/rest';
import {ShoppingApplication} from '../..';

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

before(givenAnApplication);

Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/shopping-cart.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// 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 {createClientForHandler, Client, expect} from '@loopback/testlab';
import {RestServer} from '@loopback/rest';
import {ShoppingApplication} from '../..';
import {ShoppingCartRepository} from '../../src/repositories';
Expand All @@ -13,7 +13,7 @@ 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);
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/user.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// 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 {createClientForHandler, Client, expect} from '@loopback/testlab';
import {RestServer} from '@loopback/rest';
import {ShoppingApplication} from '../..';
import {UserRepository} from '../../src/repositories';
Expand All @@ -12,7 +12,7 @@ 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 Down

0 comments on commit 293177b

Please sign in to comment.