-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmock.ts
More file actions
74 lines (70 loc) · 2.19 KB
/
Copy pathmock.ts
File metadata and controls
74 lines (70 loc) · 2.19 KB
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
import { DateTime, Option } from 'effect';
import { fixture, make } from '@effect-firebase/mock';
import { AuthorId, AuthorModel, PostId, PostModel } from '@example/shared';
const at = (iso: string) => DateTime.makeUnsafe(iso);
const author = (id: string, name: string, created: string) =>
new AuthorModel({
id: AuthorId.make(id),
name,
createdAt: at(created),
updatedAt: at(created),
});
const post = (
id: string,
title: string,
content: string,
created: string,
authorId = 'ada',
) =>
new PostModel({
id: PostId.make(id),
title,
content,
author: AuthorId.make(authorId),
createdAt: at(created),
updatedAt: at(created),
checked: false,
optional: Option.none(),
list: [],
});
/**
* A static mock backend for developing pages without the Firebase emulator.
*
* Enabled by starting the app with `VITE_MOCK_BACKEND=1` (see `app.tsx`).
* The handle is shared between the app runtime (which provides
* `mockBackend.layer` through `firestoreLayerAtom`) and the Firestore Mock
* devtools panel (which drives `mockBackend.controller`).
*/
export const mockBackend = make({
fixtures: [
fixture(AuthorModel, {
collectionPath: 'authors',
idField: 'id',
docs: [author('ada', 'Ada Lovelace', '2024-01-01T09:00:00Z')],
}),
fixture(PostModel, {
collectionPath: 'posts',
idField: 'id',
docs: [
post(
'welcome',
'Welcome to mock mode',
'This post is served from the in-memory mock backend — no emulator running. Open the TanStack Devtools panel to toggle this collection between data, empty, loading and error.',
'2024-05-03T10:00:00Z',
),
post(
'fixtures',
'Fixtures are schema-encoded',
'These documents were written through PostModel, so timestamps, references and options decode exactly like production data.',
'2024-05-02T15:30:00Z',
),
post(
'try-writing',
'Writes are live',
'Create, edit or delete posts — the mock store is reactive, so the stream behind this list re-emits just like onSnapshot.',
'2024-05-01T08:15:00Z',
),
],
}),
],
});