Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('throws an error when the target does not have any primary key', () => {
class Product extends Entity {
static definition = new ModelDefinition(
'Product',
).addProperty('categoryId', {type: Number});
}
class Category extends Entity {
static definition = new ModelDefinition('Category');
}
const productRepo = createStubInstance(DefaultCrudRepository);
const categoryRepo = createStubInstance(DefaultCrudRepository);
const relationMeta: BelongsToDefinition = {
type: RelationType.belongsTo,
targetsMany: false,
name: 'category',
source: Product,
target: () => Category,
keyFrom: 'categoryId',
// Let the relation to look up keyTo as the primary key of Category
// (which is not defined!)
keyTo: undefined,
};
expect(() =>
createBelongsToAccessor(
relationMeta,
it('throws an error when the target does not have any primary key', () => {
class Product extends Entity {
static definition = new ModelDefinition(
'Product',
).addProperty('categoryId', {type: Number});
}
class Category extends Entity {
static definition = new ModelDefinition('Category');
}
const productRepo = createStubInstance(DefaultCrudRepository);
const categoryRepo = createStubInstance(DefaultCrudRepository);
const relationMeta: BelongsToDefinition = {
type: RelationType.belongsTo,
targetsMany: false,
name: 'category',
source: Product,
target: () => Category,
keyFrom: 'categoryId',
// Let the relation to look up keyTo as the primary key of Category
// (which is not defined!)
keyTo: undefined,
};
expect(() =>
createBelongsToAccessor(
beforeEach(() => {
productRepo = createStubInstance(ProductRepository);
});
function givenStubbedCustomerRepo() {
customerRepo = createStubInstance(CustomerRepository);
}
function resetRepositories() {
todoRepo = createStubInstance(TodoRepository);
aTodo = givenTodo();
aTodoWithId = givenTodo({
id: 1,
});
aListOfTodos = [
aTodoWithId,
givenTodo({
id: 2,
title: 'so many things to do',
}),
] as Todo[];
aChangedTodo = givenTodo({
id: aTodoWithId.id,
title: 'Do some important things',
});
function givenStubbedCustomerRepo() {
customerRepo = createStubInstance(CustomerRepository);
}
function resetRepositories() {
todoListRepo = createStubInstance(TodoListRepository);
aTodoList = givenTodoList();
aTodoListWithId = givenTodoList({
id: 1,
});
aListOfTodoLists = [
aTodoListWithId,
givenTodoList({
id: 2,
title: 'a lot of todos',
}),
] as TodoList[];
aTodoListToPatchTo = givenTodoList({
title: 'changed list of todos',
});
aChangedTodoList = givenTodoList({
id: aTodoListWithId.id,
function resetRepositories() {
todoListRepo = createStubInstance(TodoListRepository);
constrainedTodoRepo = createStubInstance>(
DefaultHasManyRepository,
);
aTodoListWithId = givenTodoList({
id: 1,
});
aTodo = givenTodo();
aTodoWithId = givenTodo({id: 1});
aListOfTodos = [
aTodoWithId,
givenTodo({
id: 2,
title: 'do another thing',
}),
function givenStubbedCompanyRepo() {
customerRepo = createStubInstance(CompanyRepository);
}
function resetRepositories() {
todoListRepo = createStubInstance(TodoListRepository);
constrainedTodoRepo = createStubInstance>(
DefaultHasManyRepository,
);
aTodoListWithId = givenTodoList({
id: 1,
});
aTodo = givenTodo();
aTodoWithId = givenTodo({id: 1});
aListOfTodos = [
aTodoWithId,
givenTodo({
id: 2,
title: 'do another thing',
}),
] as Todo[];