| 1 |
import { Server, Model, belongsTo } from "miragejs"; |
| 2 |
|
| 3 |
describe("External | Shared | ORM | Belongs To | Basic | regressions", function () { |
| 4 |
test("belongsTo accessors works when foreign key is present but falsy", () => { |
| 5 |
let server = new Server({ |
| 6 |
environment: "test", |
| 7 |
models: { |
| 8 |
author: Model.extend(), |
| 9 |
post: Model.extend({ |
| 10 |
author: belongsTo(), |
| 11 |
}), |
| 12 |
}, |
| 13 |
}); |
| 14 |
|
| 15 |
server.db.loadData({ |
| 16 |
posts: [{ id: 1, authorId: 0, name: "some post" }], |
| 17 |
authors: [{ id: 0, name: "Foo" }], |
| 18 |
}); |
| 19 |
|
| 20 |
let post = server.schema.posts.find(1); |
| 21 |
expect(post.author.name).toEqual("Foo"); |
| 22 |
}); |
| 23 |
}); |