-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(example-todo-list): add navigational properties to todo-list exa…
…mple
- Loading branch information
1 parent
0737e39
commit 1e9fdd6
Showing
10 changed files
with
358 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
examples/todo-list/src/__tests__/integration/todo-list.integration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import {expect, givenHttpServerConfig} from '@loopback/testlab'; | ||
import {TodoListApplication} from '../../application'; | ||
import {Todo, TodoList} from '../../models'; | ||
import {TodoListRepository, TodoRepository} from '../../repositories'; | ||
import {givenTodo, givenTodoList} from '../helpers'; | ||
|
||
describe('TodoListApplication', () => { | ||
let app: TodoListApplication; | ||
let todoRepo: TodoRepository; | ||
let todoListRepo: TodoListRepository; | ||
|
||
before(givenRunningApplicationWithCustomConfiguration); | ||
after(() => app.stop()); | ||
|
||
before(givenTodoRepositories); | ||
|
||
it('includes Todos in find method result', async () => { | ||
const list = await givenTodoListInstance(); | ||
const todo = await givenTodoInstance({todoListId: list.id}); | ||
|
||
const response = await todoListRepo.find({ | ||
include: [{relation: 'todos'}], | ||
}); | ||
|
||
expect(response[0]).to.containEql(list); | ||
expect(response[0]).to.containEql({ | ||
todos: [todo], | ||
}); | ||
}); | ||
|
||
it('includes Todos in findById result', async () => { | ||
const list = await givenTodoListInstance(); | ||
const todo = await givenTodoInstance({todoListId: list.id}); | ||
|
||
const response = await todoListRepo.findById(list.id, { | ||
include: [{relation: 'todos'}], | ||
}); | ||
|
||
expect(response).to.containEql(list); | ||
expect(response).to.containEql({ | ||
todos: [todo], | ||
}); | ||
}); | ||
|
||
// TOOD: refactor this to the helpers file so it's not duplicated | ||
|
||
async function givenRunningApplicationWithCustomConfiguration() { | ||
app = new TodoListApplication({ | ||
rest: givenHttpServerConfig(), | ||
}); | ||
|
||
await app.boot(); | ||
|
||
/** | ||
* Override default config for DataSource for testing so we don't write | ||
* test data to file when using the memory connector. | ||
*/ | ||
app.bind('datasources.config.db').to({ | ||
name: 'db', | ||
connector: 'memory', | ||
}); | ||
|
||
// Start Application | ||
await app.start(); | ||
} | ||
|
||
async function givenTodoRepositories() { | ||
todoRepo = await app.getRepository(TodoRepository); | ||
todoListRepo = await app.getRepository(TodoListRepository); | ||
} | ||
|
||
async function givenTodoInstance(todo?: Partial<Todo>) { | ||
return await todoRepo.create(givenTodo(todo)); | ||
} | ||
|
||
async function givenTodoListInstance(data?: Partial<TodoList>) { | ||
return await todoListRepo.create(givenTodoList(data)); | ||
} | ||
}); |
79 changes: 79 additions & 0 deletions
79
examples/todo-list/src/__tests__/integration/todo.integration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import {expect, givenHttpServerConfig} from '@loopback/testlab'; | ||
import {TodoListApplication} from '../../application'; | ||
import {Todo, TodoList} from '../../models'; | ||
import {TodoListRepository, TodoRepository} from '../../repositories'; | ||
import {givenTodo, givenTodoList} from '../helpers'; | ||
|
||
describe('TodoApplication', () => { | ||
let app: TodoListApplication; | ||
let todoRepo: TodoRepository; | ||
let todoListRepo: TodoListRepository; | ||
|
||
before(givenRunningApplicationWithCustomConfiguration); | ||
after(() => app.stop()); | ||
|
||
before(givenTodoRepositories); | ||
|
||
it('includes TodoList in find method result', async () => { | ||
const list = await givenTodoListInstance(); | ||
const todo = await givenTodoInstance({todoListId: list.id}); | ||
|
||
const response = await todoRepo.find({ | ||
include: [{relation: 'todoList'}], | ||
}); | ||
|
||
expect(response[0]).to.containEql(todo); | ||
expect(response[0]).to.containEql({ | ||
todoList: list, | ||
}); | ||
}); | ||
|
||
it('includes TodoList in findById result', async () => { | ||
const list = await givenTodoListInstance({color: 'grey'}); | ||
const todo = await givenTodoInstance({todoListId: list.id}); | ||
|
||
const response = await todoRepo.findById(todo.id, { | ||
include: [{relation: 'todoList'}], | ||
}); | ||
|
||
expect(response).to.containEql(todo); | ||
expect(response).to.containEql({ | ||
todoList: list, | ||
}); | ||
}); | ||
|
||
// TOOD: refactor this to the helpers file so it's not duplicated | ||
|
||
async function givenRunningApplicationWithCustomConfiguration() { | ||
app = new TodoListApplication({ | ||
rest: givenHttpServerConfig(), | ||
}); | ||
|
||
await app.boot(); | ||
|
||
/** | ||
* Override default config for DataSource for testing so we don't write | ||
* test data to file when using the memory connector. | ||
*/ | ||
app.bind('datasources.config.db').to({ | ||
name: 'db', | ||
connector: 'memory', | ||
}); | ||
|
||
// Start Application | ||
await app.start(); | ||
} | ||
|
||
async function givenTodoRepositories() { | ||
todoRepo = await app.getRepository(TodoRepository); | ||
todoListRepo = await app.getRepository(TodoListRepository); | ||
} | ||
|
||
async function givenTodoInstance(todo?: Partial<Todo>) { | ||
return await todoRepo.create(givenTodo(todo)); | ||
} | ||
|
||
async function givenTodoListInstance(data?: Partial<TodoList>) { | ||
return await todoListRepo.create(givenTodoList(data)); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.