node.js - 外键茉莉花测试失败
问题描述
我有 2 个名为users
并orders
提供模型的表:
export type User = {
id?: number;
firstname: string;
lastname: string;
password: string;
role: string;
email: string;
};
export type Order = {
id?: number;
userId: number;
status: string;
};
我在创建用户时测试失败:
it('create method should add an order', async () => {
const result = await store.create({
id: 1,
userId: 1,
status: 'open',
});
expect(result).toEqual({
id: 1,
userId: 1,
status: 'open',
});
});
错误堆栈:
1) Order Model create method should add an order
Message:
Error: Could not add new order for user ID 1 for Error: error: insert or update on table "orders" violates foreign key constraint "orders_user_id_fkey"
显然,问题是数据库中不存在下订单的用户。因此,作为一种解决方案,我尝试在此测试中创建一个用户,但这会破坏 users_spec.ts 文件中的顺序测试。
如何正确编写此测试?
解决方案
推荐阅读
- python-3.x - 为每个列表值添加一个项目
- python - Python:在for循环中强制字典中的值复制
- python - 使用 Python 删除和替换特定的字符串索引
- regex - 无法正确解析文件;全球不工作
- c++ - 如何实现与参数顺序无关的 std::same_as 的广义形式(即对于两个以上的类型参数)?
- python - Scrapy crawl 在终端中显示输出,但在 json excel 文件中不显示
- python - 从检查点恢复失败。这很可能是由于检查点中缺少变量名称或其他图形键
- python - 使用 python 烧瓶读取 owl 文件
- php - Facade.php(第 218 行)Laravel 5.4 中尚未设置外观根。路线有问题?
- httprequest - Google Assistant 自定义打开 url 命令