Debian Codegraph @

__tests__/external/shared/serializers/base/assorted-collections-test.js

raw
1 import { Server, Model, Serializer } from "miragejs";
2
3 describe("External | Shared | Serializers | Base | Assorted Collections", function () {
4 let server;
5
6 beforeEach(function () {
7 server = new Server({
8 models: {
9 wordSmith: Model,
10 greatPhoto: Model,
11 },
12
13 serializers: {
14 application: Serializer,
15 greatPhoto: Serializer.extend({
16 attrs: ["id", "title"],
17 }),
18 },
19 });
20 });
21
22 afterEach(function () {
23 server.shutdown();
24 });
25
26 test(`an array of assorted collections can be serialized`, () => {
27 let wordSmiths = [
28 { id: "1", name: "Link" },
29 { id: "2", name: "Zelda" },
30 { id: "3", name: "Epona" },
31 ];
32 let greatPhotos = [
33 { id: "1", title: "Amazing", location: "Hyrule" },
34 { id: "2", title: "greatPhoto", location: "Goron City" },
35 ];
36
37 server.db.loadData({ wordSmiths, greatPhotos });
38
39 let result = server.serializerOrRegistry.serialize([
40 server.schema.wordSmiths.all(),
41 server.schema.greatPhotos.all(),
42 ]);
43
44 expect(result).toEqual({
45 wordSmiths: wordSmiths,
46 greatPhotos: greatPhotos.map((attrs) => {
47 delete attrs.location;
48 return attrs;
49 }),
50 });
51 });
52 });