Skip to content

Commit

Permalink
fix: fix improper response code
Browse files Browse the repository at this point in the history
fix improper server response code
  • Loading branch information
Hage Yaapa committed Aug 17, 2018
1 parent 18342db commit 151f25b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class DefaultCrudRepository<T extends Entity, ID>
this.modelClass = dataSource.createModel<juggler.PersistedModelClass>(
definition.name,
properties,
Object.assign({strict: true}, definition.settings),
Object.assign({strict: true}, {strictDelete: true}, definition.settings),
);
this.modelClass.attachTo(dataSource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ describe('CrudRepositoryImpl', () => {
it('delete all entities', async () => {
await repo.create({id: 1, email: '[email protected]'});
await repo.create({id: 2, email: '[email protected]'});
const count = await repo.deleteAll();
expect(count).to.be.eql(2);
const deleteCount = await repo.deleteAll();
expect(deleteCount).to.be.eql(2);
const count = await repo.count();
expect(count).to.be.eql(0);
});

it('count all entities', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,40 @@ describe('DefaultCrudRepository', () => {
it('implements Repository.delete()', async () => {
const repo = new DefaultCrudRepository(Note, ds);
const note = await repo.create({title: 't3', content: 'c3'});
const result = await repo.delete(note);
expect(result).to.eql(true);
const deleteResult = await repo.delete(note);
expect(deleteResult).to.eql(true);
const findResult = await repo.find({where: {title: 't3'}});
expect(findResult.length).to.eql(0);
});

it('implements Repository.deleteById()', async () => {
const repo = new DefaultCrudRepository(Note, ds);
const note = await repo.create({title: 't3', content: 'c3'});
const result = await repo.deleteById(note.id);
expect(result).to.eql(true);
await expect(repo.findById(note.id)).to.be.rejectedWith(
`no ${repo.modelClass.name} found with id "${note.id}"`,
);
});

it('implements Repository.deleteAll()', async () => {
const repo = new DefaultCrudRepository(Note, ds);
await repo.create({title: 't3', content: 'c3'});
await repo.create({title: 't4', content: 'c4'});
const result = await repo.deleteAll({title: 't3'});
expect(result).to.eql(1);
const deleteCount = await repo.deleteAll();
expect(deleteCount).to.eql(2);
const count = await repo.count();
expect(count).to.eql(0);
});

it('implements Repository.deleteAll(<where>)', async () => {
const repo = new DefaultCrudRepository(Note, ds);
await repo.create({title: 't3', content: 'c3'});
await repo.create({title: 't4', content: 'c4'});
const deleteCount = await repo.deleteAll({title: 't3'});
expect(deleteCount).to.eql(1);
const result = await repo.findOne({where: {title: 't3'}});
expect(result).to.eql(null);
});

it('implements Repository.updateById()', async () => {
Expand Down

0 comments on commit 151f25b

Please sign in to comment.