Skip to content
Permalink
Browse files

fix: fix import statements

  • Loading branch information...
nabdelgadir committed Aug 12, 2019
1 parent 1fb034f commit 7710fba73faec91881dabe9f2b58bd5ae97ed823
Showing with 700 additions and 104 deletions.
  1. +535 −0 packages/repository-tests/package-lock.json
  2. +6 −3 packages/repository-tests/package.json
  3. +17 −8 packages/repository-tests/src/__tests__/acceptance/belongs-to.relation.acceptance.ts
  4. +17 −8 ...eptance/{has-many-without-id.relation.acceptance.ts → has-many-without-di.relation.acceptance.ts}
  5. +17 −12 packages/repository-tests/src/__tests__/acceptance/has-many.relation.acceptance.ts
  6. +33 −26 packages/repository-tests/src/__tests__/acceptance/has-one.relation.acceptance.ts
  7. +23 −17 packages/repository-tests/src/__tests__/acceptance/repository.acceptance.ts
  8. +1 −1 packages/repository-tests/src/__tests__/fixtures/models/address.model.ts
  9. +8 −1 packages/repository-tests/src/__tests__/fixtures/models/customer.model.ts
  10. +1 −1 packages/repository-tests/src/__tests__/fixtures/models/order.model.ts
  11. +1 −1 packages/repository-tests/src/__tests__/fixtures/models/product.model.ts
  12. +1 −1 packages/repository-tests/src/__tests__/fixtures/models/shipment.model.ts
  13. +1 −1 packages/repository-tests/src/__tests__/fixtures/repositories/address.repository.ts
  14. +2 −2 packages/repository-tests/src/__tests__/fixtures/repositories/customer.repository.ts
  15. +1 −1 packages/repository-tests/src/__tests__/fixtures/repositories/order.repository.ts
  16. +1 −2 packages/repository-tests/src/__tests__/fixtures/repositories/product.repository.ts
  17. +2 −2 packages/repository-tests/src/__tests__/fixtures/repositories/shipment.repository.ts
  18. +33 −17 packages/repository-tests/src/__tests__/integration/repositories/relation.factory.integration.ts

Large diffs are not rendered by default.

@@ -23,14 +23,17 @@
"@loopback/build": "^1.7.1",
"@loopback/repository": "^1.10.1",
"@types/debug": "^4.1.5",
"@types/node": "^10.14.15"
"@types/node": "^10.14.15",
"@types/lodash": "^4.14.136"
},
"dependencies": {
"loopback-datasource-juggler": "^4.11.0",
"lodash": "^4.17.15",
"@loopback/testlab": "^1.7.2",
"@types/debug": "^4.1.5",
"debug": "^4.1.1",
"@loopback/context": "1.21.1",
"@loopback/core": "1.9.0"
"@loopback/context": "^1.21.1",
"@loopback/core": "^1.9.0"
},
"peerDependencies": {
"@loopback/repository": "^1.6.1"
@@ -3,10 +3,19 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import { Application } from '@loopback/core';
import { expect } from '@loopback/testlab';
import { ApplicationWithRepositories, juggler, repository, RepositoryMixin } from '../..';
import { CustomerRepository, OrderRepository, ShipmentRepository } from '../fixtures/repositories';
import {Application} from '@loopback/core';
import {
ApplicationWithRepositories,
juggler,
repository,
RepositoryMixin,
} from '@loopback/repository';
import {expect} from '@loopback/testlab';
import {
CustomerRepository,
OrderRepository,
ShipmentRepository,
} from '../fixtures/repositories';

describe('BelongsTo relation', () => {
// Given a Customer and Order models - see definitions at the bottom
@@ -26,7 +35,7 @@ describe('BelongsTo relation', () => {
});

it('can find customer of order', async () => {
const customer = await customerRepo.create({ name: 'Order McForder' });
const customer = await customerRepo.create({name: 'Order McForder'});
const order = await orderRepo.create({
customerId: customer.id,
description: 'Order from Order McForder, the hoarder of Mordor',
@@ -53,7 +62,7 @@ describe('BelongsTo relation', () => {
class OrderController {
constructor(
@repository(OrderRepository) protected orderRepository: OrderRepository,
) { }
) {}

async findOwnerOfOrder(orderId: string) {
return this.orderRepository.customer(orderId);
@@ -65,9 +74,9 @@ describe('BelongsTo relation', () => {
}

function givenApplicationWithMemoryDB() {
class TestApp extends RepositoryMixin(Application) { }
class TestApp extends RepositoryMixin(Application) {}
app = new TestApp();
app.dataSource(new juggler.DataSource({ name: 'db', connector: 'memory' }));
app.dataSource(new juggler.DataSource({name: 'db', connector: 'memory'}));
}

async function givenBoundCrudRepositories() {
@@ -3,9 +3,18 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import { expect } from '@loopback/testlab';
import { DefaultCrudRepository, Entity, EntityCrudRepository, Getter, hasMany, HasManyRepositoryFactory, juggler, model, property } from '../..';

import {Getter} from '@loopback/context';
import {
DefaultCrudRepository,
Entity,
EntityCrudRepository,
hasMany,
HasManyRepositoryFactory,
juggler,
model,
property,
} from '@loopback/repository';
import {expect} from '@loopback/testlab';
describe('HasMany relation', () => {
// Given a Customer and Order models - see definitions at the bottom

@@ -64,7 +73,7 @@ describe('HasMany relation', () => {
expect(orders).to.not.containEql(notMyOrder);

const persisted = await orderRepo.find({
where: { customerId: existingCustomerId },
where: {customerId: existingCustomerId},
});
expect(persisted).to.deepEqual(orders);
});
@@ -112,7 +121,7 @@ describe('HasMany relation', () => {
class OrderRepository extends DefaultCrudRepository<
Order,
typeof Order.prototype.id
> {
> {
constructor(db: juggler.DataSource) {
super(Order, db);
}
@@ -121,7 +130,7 @@ describe('HasMany relation', () => {
class CustomerRepository extends DefaultCrudRepository<
Customer,
typeof Customer.prototype.id
> {
> {
public readonly orders: HasManyRepositoryFactory<
Order,
typeof Customer.prototype.id
@@ -142,7 +151,7 @@ describe('HasMany relation', () => {
}

function givenDataSource() {
ds = new juggler.DataSource({ connector: 'memory' });
ds = new juggler.DataSource({connector: 'memory'});
}

function givenOrderRepository() {
@@ -154,6 +163,6 @@ describe('HasMany relation', () => {
}

async function givenPersistedCustomerInstance() {
return customerRepo.create({ name: 'a customer' });
return customerRepo.create({name: 'a customer'});
}
});
@@ -3,12 +3,17 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import { Application } from '@loopback/core';
import { expect } from '@loopback/testlab';
import {Application} from '@loopback/core';
import {
ApplicationWithRepositories,
juggler,
repository,
RepositoryMixin,
} from '@loopback/repository';
import {expect} from '@loopback/testlab';
import * as _ from 'lodash';
import { ApplicationWithRepositories, juggler, repository, RepositoryMixin } from '../..';
import { Customer, Order } from '../fixtures/models';
import { CustomerRepository, OrderRepository } from '../fixtures/repositories';
import {Customer, Order} from '../fixtures/models';
import {CustomerRepository, OrderRepository} from '../fixtures/repositories';

describe('HasMany relation', () => {
// Given a Customer and Order models - see definitions at the bottom
@@ -59,7 +64,7 @@ describe('HasMany relation', () => {
expect(foundOrders).to.not.containEql(notMyOrder);

const persisted = await orderRepo.find({
where: { customerId: existingCustomerId },
where: {customerId: existingCustomerId},
});
expect(persisted).to.deepEqual(foundOrders);
});
@@ -73,7 +78,7 @@ describe('HasMany relation', () => {
description: 'order 2',
isShipped: false,
});
const patchObject = { isShipped: true };
const patchObject = {isShipped: true};
const arePatched = await controller.patchCustomerOrders(
existingCustomerId,
patchObject,
@@ -149,7 +154,7 @@ describe('HasMany relation', () => {

context('when targeting the source model', () => {
it('gets the parent entity through the child entity', async () => {
const parent = await customerRepo.create({ name: 'parent customer' });
const parent = await customerRepo.create({name: 'parent customer'});
const child = await customerRepo.create({
name: 'child customer',
parentId: parent.id,
@@ -183,7 +188,7 @@ describe('HasMany relation', () => {
constructor(
@repository(CustomerRepository)
protected customerRepository: CustomerRepository,
) { }
) {}

async createCustomerOrders(
customerId: number,
@@ -221,10 +226,10 @@ describe('HasMany relation', () => {
}

function givenApplicationWithMemoryDB() {
class TestApp extends RepositoryMixin(Application) { }
class TestApp extends RepositoryMixin(Application) {}

app = new TestApp();
app.dataSource(new juggler.DataSource({ name: 'db', connector: 'memory' }));
app.dataSource(new juggler.DataSource({name: 'db', connector: 'memory'}));
}

async function givenBoundCrudRepositoriesForCustomerAndOrder() {
@@ -242,6 +247,6 @@ describe('HasMany relation', () => {
}

async function givenPersistedCustomerInstance() {
return customerRepo.create({ name: 'a customer' });
return customerRepo.create({name: 'a customer'});
}
});
@@ -3,11 +3,18 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import { Application } from '@loopback/core';
import { expect, toJSON } from '@loopback/testlab';
import { ApplicationWithRepositories, EntityNotFoundError, Filter, juggler, repository, RepositoryMixin } from '../..';
import { Address } from '../fixtures/models';
import { AddressRepository, CustomerRepository } from '../fixtures/repositories';
import {Application} from '@loopback/core';
import {
ApplicationWithRepositories,
EntityNotFoundError,
Filter,
juggler,
repository,
RepositoryMixin,
} from '@loopback/repository';
import {expect, toJSON} from '@loopback/testlab';
import {Address} from '../fixtures/models';
import {AddressRepository, CustomerRepository} from '../fixtures/repositories';

describe('hasOne relation', () => {
// Given a Customer and Address models - see definitions at the bottom
@@ -72,7 +79,7 @@ describe('hasOne relation', () => {
expect(toJSON(foundAddress)).to.deepEqual(toJSON(address));

const persisted = await addressRepo.find({
where: { customerId: existingCustomerId },
where: {customerId: existingCustomerId},
});
expect(persisted[0]).to.deepEqual(foundAddress);
});
@@ -85,12 +92,12 @@ describe('hasOne relation', () => {
// not accepted in the filter object for the get() method
// if the following line is uncommented
{
where: { street: '456 test road' },
where: {street: '456 test road'},
},
);

const persisted = await addressRepo.find({
where: { customerId: existingCustomerId },
where: {customerId: existingCustomerId},
});
// TODO: make sure this test fails when where condition is supplied
// compiler should have errored out (?)
@@ -116,13 +123,13 @@ describe('hasOne relation', () => {
province: 'Rhone',
});

const patchObject = { city: 'Lyon-Genas' };
const patchObject = {city: 'Lyon-Genas'};
const arePatched = await controller.patchCustomerAddress(
existingCustomerId,
patchObject,
);

expect(arePatched).to.deepEqual({ count: 1 });
expect(arePatched).to.deepEqual({count: 1});
const patchedData = await addressRepo.findById(address.zipcode);
expect(toJSON(patchedData)).to.deepEqual({
customerId: existingCustomerId,
@@ -134,20 +141,20 @@ describe('hasOne relation', () => {
});

it('patches the related instance only', async () => {
const bob = await customerRepo.create({ name: 'Bob' });
await customerRepo.address(bob.id).create({ city: 'Paris' });
const bob = await customerRepo.create({name: 'Bob'});
await customerRepo.address(bob.id).create({city: 'Paris'});

const alice = await customerRepo.create({ name: 'Alice' });
await customerRepo.address(alice.id).create({ city: 'London' });
const alice = await customerRepo.create({name: 'Alice'});
await customerRepo.address(alice.id).create({city: 'London'});

const result = await controller.patchCustomerAddress(alice.id, {
city: 'New York',
});

expect(result).to.deepEqual({ count: 1 });
expect(result).to.deepEqual({count: 1});

const found = await customerRepo.address(bob.id).get();
expect(toJSON(found)).to.containDeep({ city: 'Paris' });
expect(toJSON(found)).to.containDeep({city: 'Paris'});
});

it('throws an error when PATCH tries to change the foreignKey', async () => {
@@ -169,23 +176,23 @@ describe('hasOne relation', () => {
const areDeleted = await controller.deleteCustomerAddress(
existingCustomerId,
);
expect(areDeleted).to.deepEqual({ count: 1 });
expect(areDeleted).to.deepEqual({count: 1});

await expect(
controller.findCustomerAddress(existingCustomerId),
).to.be.rejectedWith(EntityNotFoundError);
});

it('deletes the related model instance only', async () => {
const bob = await customerRepo.create({ name: 'Bob' });
await customerRepo.address(bob.id).create({ city: 'Paris' });
const bob = await customerRepo.create({name: 'Bob'});
await customerRepo.address(bob.id).create({city: 'Paris'});

const alice = await customerRepo.create({ name: 'Alice' });
await customerRepo.address(alice.id).create({ city: 'London' });
const alice = await customerRepo.create({name: 'Alice'});
await customerRepo.address(alice.id).create({city: 'London'});

const result = await controller.deleteCustomerAddress(alice.id);

expect(result).to.deepEqual({ count: 1 });
expect(result).to.deepEqual({count: 1});

const found = await addressRepo.find();
expect(found).to.have.length(1);
@@ -197,7 +204,7 @@ describe('hasOne relation', () => {
constructor(
@repository(CustomerRepository)
protected customerRepository: CustomerRepository,
) { }
) {}

async createCustomerAddress(
customerId: number,
@@ -229,9 +236,9 @@ describe('hasOne relation', () => {
}

function givenApplicationWithMemoryDB() {
class TestApp extends RepositoryMixin(Application) { }
class TestApp extends RepositoryMixin(Application) {}
app = new TestApp();
app.dataSource(new juggler.DataSource({ name: 'db', connector: 'memory' }));
app.dataSource(new juggler.DataSource({name: 'db', connector: 'memory'}));
}

async function givenBoundCrudRepositoriesForCustomerAndAddress() {
@@ -249,6 +256,6 @@ describe('hasOne relation', () => {
}

async function givenPersistedCustomerInstance() {
return customerRepo.create({ name: 'a customer' });
return customerRepo.create({name: 'a customer'});
}
});

0 comments on commit 7710fba

Please sign in to comment.
You can’t perform that action at this time.