tachybase_todo/packages/actions/src/__tests__/add.test.ts
Junyi 53729e188a
Refactor: change global injection of test for actions package. (#15)
* Refactor: change global injection to index.ts to simplify all test files.

* Fix: typo.
2020-11-16 20:38:56 +08:00

24 lines
666 B
TypeScript

import { initDatabase, agent } from './index';
describe('add', () => {
let db;
beforeEach(async () => {
db = await initDatabase();
});
afterAll(() => db.close());
it('belongsToMany1', async () => {
const [Post, Tag] = db.getModels(['posts', 'tags']);
let post = await Post.create();
let tag1 = await Tag.create({name: 'tag1'});
let tag2 = await Tag.create({name: 'tag2'});
await agent.post(`/posts/${post.id}/tags:add/${tag1.id}`);
await agent.post(`/posts/${post.id}/tags:add/${tag2.id}`);
let [tag01, tag02] = await post.getTags();
expect(tag01.id).toBe(tag1.id);
expect(tag02.id).toBe(tag2.id);
});
});