| 1 |
import { Server, Model, hasMany } from "miragejs"; |
| 2 |
|
| 3 |
describe("External | Shared | ORM | Has Many | Regressions | Many to many inverse set bug", () => { |
| 4 |
let server; |
| 5 |
|
| 6 |
beforeEach(() => { |
| 7 |
server = new Server({ |
| 8 |
environment: "test", |
| 9 |
models: { |
| 10 |
post: Model.extend({ |
| 11 |
tags: hasMany(), |
| 12 |
}), |
| 13 |
tag: Model.extend({ |
| 14 |
posts: hasMany(), |
| 15 |
}), |
| 16 |
}, |
| 17 |
}); |
| 18 |
}); |
| 19 |
|
| 20 |
test(`it works`, () => { |
| 21 |
server.db.loadData({ |
| 22 |
posts: [ |
| 23 |
{ id: "1", tagIds: ["15", "16"] }, |
| 24 |
{ id: "2", tagIds: ["16"] }, |
| 25 |
], |
| 26 |
tags: [ |
| 27 |
{ id: "15", postIds: ["1"] }, |
| 28 |
{ id: "16", postIds: ["1", "2"] }, |
| 29 |
], |
| 30 |
}); |
| 31 |
|
| 32 |
server.schema.posts.find(1).update({ tagIds: ["15"] }); |
| 33 |
|
| 34 |
expect(server.db.posts.find(1).tagIds).toEqual(["15"]); |
| 35 |
expect(server.db.tags.find(15).postIds).toEqual(["1"]); |
| 36 |
expect(server.db.tags.find(16).postIds).toEqual(["2"]); |
| 37 |
}); |
| 38 |
}); |