-
Notifications
You must be signed in to change notification settings - Fork 73
/
fixture.ts
248 lines (235 loc) · 5.7 KB
/
fixture.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import { IEntity } from '../src';
import { Serialize } from '../src/Decorators/Serialize';
export class Coordinates {
latitude: number;
longitude: number;
}
export class FirestoreDocumentReference {
id: string;
path: string;
}
export class AlbumImage {
id: string;
url: string;
}
export class Album {
id: string;
name: string;
releaseDate: Date;
comment?: string;
}
export class Website {
url: string;
}
export class Agent {
name: string;
@Serialize(Website)
website: Website;
}
export class Band {
id: string;
name: string;
formationYear: number;
lastShow: Date;
lastShowCoordinates?: Coordinates;
genres: Array<string>;
}
export const getInitialData = () => {
return [
{
id: 'porcupine-tree',
name: 'Porcupine Tree',
formationYear: 1987,
lastShow: new Date('2010-10-14'),
lastShowCoordinates: { latitude: 51.5009088, longitude: -0.1795547 },
genres: ['psychedelic-rock', 'progressive-rock', 'progressive-metal'],
albums: [
{
id: 'lightbulb-sun',
name: 'Lightbulb Sun',
releaseDate: new Date('2000-05-22'),
images: [
{
id: 'album-artwork',
url: 'http://lorempixel.com/100/100',
},
],
},
{
id: 'in-absentia',
name: 'In Absentia',
releaseDate: new Date('2002-09-24'),
images: [
{
id: 'album-artwork',
url: 'http://lorempixel.com/100/100',
},
],
},
{
id: 'deadwing',
name: 'Deadwing',
releaseDate: new Date('2005-03-25'),
images: [
{
id: 'album-artwork',
url: 'http://lorempixel.com/100/100',
},
],
},
{
id: 'fear-blank-planet',
name: 'Fear of a Blank Planet',
releaseDate: new Date('2007-04-16'),
images: [
{
id: 'album-artwork',
url: 'http://lorempixel.com/100/100',
},
{
id: 'album-cover',
url: 'http://lorempixel.com/100/100',
},
],
},
],
},
{
id: 'pink-floyd',
name: 'Pink Floyd',
formationYear: 1965,
lastShow: new Date('1981-06-17'),
genres: ['psychedelic-rock', 'progressive-rock', 'space-rock'],
albums: [
{
id: 'dark-side-moon',
name: 'The Dark Side of the Moon',
releaseDate: new Date('1973-03-01'),
images: [
{
id: 'album-artwork',
url: 'http://lorempixel.com/100/100',
},
],
},
{
id: 'wish-you-were-here',
name: 'Wish You Were Here',
releaseDate: new Date('1975-09-12'),
images: [
{
id: 'album-artwork',
url: 'http://lorempixel.com/100/100',
},
],
},
{
id: 'animals',
name: 'Animals',
releaseDate: new Date('1977-01-23'),
images: [
{
id: 'album-artwork',
url: 'http://lorempixel.com/100/100',
},
],
},
{
id: 'the-wall',
name: 'The Wall',
releaseDate: new Date('1979-11-30'),
images: [],
},
],
},
{
id: 'red-hot-chili-peppers',
name: 'Red Hot Chili Peppers',
formationYear: 1983,
lastShow: null,
genres: ['funk-rock', 'funk-metal', 'alternative-rock'],
albums: [
{
id: 'californication',
name: 'Californication',
releaseDate: new Date('1999-06-08'),
images: [
{
id: 'album-artwork',
url: 'http://lorempixel.com/100/100',
},
],
},
{
id: 'by-the-way',
name: 'By the Way',
releaseDate: new Date('2002-07-09'),
images: [
{
id: 'album-artwork',
url: 'http://lorempixel.com/100/100',
},
],
},
{
id: 'stadium-arcadium',
name: 'Stadium Arcadium',
releaseDate: new Date('2006-05-09'),
images: [
{
id: 'album-artwork',
url: 'http://lorempixel.com/100/100',
},
],
},
],
},
{
id: 'the-speckled-band',
name: 'the Speckled Band',
formationYear: 1892,
lastShow: null,
genres: [],
albums: [],
agents: [
{
name: 'Mycroft Holmes',
website: {
url: 'en.wikipedia.org/wiki/Mycroft_Holmes',
},
},
{
name: 'Arthur Conan Doyle',
website: {
url: 'en.wikipedia.org/wiki/Arthur_Conan_Doyle',
},
},
],
},
];
};
const getCollectionBoilerplate = (entity: string, hash: Record<string, unknown>) => ({
__collection__: {
[entity]: {
__doc__: hash,
},
},
});
export const getBandFixture = () => {
const initialData = getInitialData();
const objectifyList = (arr: Array<IEntity>, cb?) =>
arr.reduce((acc, cur) => ({ ...acc, [cur.id]: cb ? cb(cur) : cur }), {});
return objectifyList(initialData, ({ albums, ...rest }) => ({
...rest,
...getCollectionBoilerplate(
'albums',
objectifyList(albums, ({ images, ...album }) => ({
...album,
...getCollectionBoilerplate('images', objectifyList(images)),
}))
),
}));
};
export const getFixture = () => {
return getCollectionBoilerplate('bands', getBandFixture());
};