deno.land / x / replicache@v10.0.0-beta.0 / new-phone-who-dis.test.ts

new-phone-who-dis.test.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
import {expect} from '@esm-bundle/chai';import * as sinon from 'sinon';import type {Puller} from './puller.js';import type {Pusher} from './pusher.js';import type {Poke} from './replicache.js';import { expectLogContext, initReplicacheTesting, replicacheForTesting, tickAFewTimes,} from './test-util.js';
initReplicacheTesting();
test('pull returning ClientStateNotFoundResponse should call onClientStateNotFound', async () => { const puller: Puller = async _req => { return { httpRequestInfo: {httpStatusCode: 200, errorMessage: ''}, response: { error: 'ClientStateNotFound', }, }; }; const pusher: Pusher = async _req => { return {httpStatusCode: 200, errorMessage: ''}; };
const consoleErrorStub = sinon.stub(console, 'error'); const onClientStateNotFound = sinon.fake();
const rep = await replicacheForTesting('new-phone', { puller, pusher, onClientStateNotFound, });
// One pull from open
expect(onClientStateNotFound.callCount).to.equal(1); expect(onClientStateNotFound.lastCall.args).to.deep.equal([ {type: 'NotFoundOnServer'}, ]);
expectLogContext( consoleErrorStub, 0, rep, `Client state not found, clientID: ${await rep.clientID}`, );
rep.pull(); await tickAFewTimes();
expect(onClientStateNotFound.callCount).to.equal(2); expect(onClientStateNotFound.lastCall.args).to.deep.equal([ {type: 'NotFoundOnServer'}, ]); expectLogContext( consoleErrorStub, 1, rep, `Client state not found, clientID: ${await rep.clientID}`, );});
test('poke with ClientStateNotFoundResponse should call onClientStateNotFound', async () => { const puller: Puller = async _req => { return { httpRequestInfo: {httpStatusCode: 200, errorMessage: ''}, }; };
const consoleErrorStub = sinon.stub(console, 'error'); const onClientStateNotFound = sinon.fake();
const rep = await replicacheForTesting('new-phone', { puller, onClientStateNotFound, });
const pokeBody: Poke = { baseCookie: null, pullResponse: {error: 'ClientStateNotFound'}, }; await rep.poke(pokeBody);
expect(onClientStateNotFound.callCount).to.equal(1); expect(onClientStateNotFound.lastCall.args).to.deep.equal([ {type: 'NotFoundOnServer'}, ]); expect(consoleErrorStub.callCount).to.equal(1); expectLogContext( consoleErrorStub, 0, rep, `Client state not found, clientID: ${await rep.clientID}`, );});
replicache

Version Info

Tagged at
2 years ago