Skip to content

Commit

Permalink
fix: fix import statements
Browse files Browse the repository at this point in the history
  • Loading branch information
nabdelgadir committed Aug 12, 2019
1 parent 1fb034f commit 7710fba
Show file tree
Hide file tree
Showing 18 changed files with 700 additions and 104 deletions.
535 changes: 535 additions & 0 deletions packages/repository-tests/package-lock.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions packages/repository-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -53,7 +62,7 @@ describe('BelongsTo relation', () => {
class OrderController {
constructor(
@repository(OrderRepository) protected orderRepository: OrderRepository,
) { }
) {}

async findOwnerOfOrder(orderId: string) {
return this.orderRepository.customer(orderId);
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -112,7 +121,7 @@ describe('HasMany relation', () => {
class OrderRepository extends DefaultCrudRepository<
Order,
typeof Order.prototype.id
> {
> {
constructor(db: juggler.DataSource) {
super(Order, db);
}
Expand All @@ -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
Expand All @@ -142,7 +151,7 @@ describe('HasMany relation', () => {
}

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

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

async function givenPersistedCustomerInstance() {
return customerRepo.create({ name: 'a customer' });
return customerRepo.create({name: 'a customer'});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
});
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -183,7 +188,7 @@ describe('HasMany relation', () => {
constructor(
@repository(CustomerRepository)
protected customerRepository: CustomerRepository,
) { }
) {}

async createCustomerOrders(
customerId: number,
Expand Down Expand Up @@ -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() {
Expand All @@ -242,6 +247,6 @@ describe('HasMany relation', () => {
}

async function givenPersistedCustomerInstance() {
return customerRepo.create({ name: 'a customer' });
return customerRepo.create({name: 'a customer'});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
});
Expand All @@ -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 (?)
Expand All @@ -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,
Expand All @@ -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 () => {
Expand All @@ -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);
Expand All @@ -197,7 +204,7 @@ describe('hasOne relation', () => {
constructor(
@repository(CustomerRepository)
protected customerRepository: CustomerRepository,
) { }
) {}

async createCustomerAddress(
customerId: number,
Expand Down Expand Up @@ -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() {
Expand All @@ -249,6 +256,6 @@ describe('hasOne relation', () => {
}

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

0 comments on commit 7710fba

Please sign in to comment.