|
1 | | -import {Synclet} from 'synclets'; |
| 1 | +import {Synclet, Timestamp, Value} from 'synclets'; |
2 | 2 | import {ValueConnector} from 'synclets/connector/value'; |
3 | 3 | import {MemoryTransport} from 'synclets/transport/memory'; |
4 | 4 |
|
5 | 5 | test('value sync', async () => { |
6 | 6 | class TestValueConnector extends ValueConnector { |
7 | | - private value: string = ''; |
| 7 | + #value: Value = 'V1'; |
| 8 | + #timestamp: Timestamp = ''; |
| 9 | + |
8 | 10 | async getValue() { |
9 | | - return this.value; |
| 11 | + return this.#value; |
| 12 | + } |
| 13 | + async setValue(value: Value) { |
| 14 | + this.#value = value; |
10 | 15 | } |
11 | | - async setValue(value: string) { |
12 | | - this.value = value; |
| 16 | + async getValueTimestamp() { |
| 17 | + return this.#timestamp; |
13 | 18 | } |
| 19 | + async setValueTimestamp(timestamp: Timestamp) { |
| 20 | + this.#timestamp = timestamp; |
| 21 | + } |
| 22 | + |
14 | 23 | getUnderlyingValue() { |
15 | | - return this.value; |
| 24 | + return this.#value; |
16 | 25 | } |
17 | | - setUnderlyingValue(value: string) { |
18 | | - this.value = value; |
| 26 | + async setUnderlyingValue(value: Value) { |
| 27 | + this.#value = value; |
| 28 | + await this.valueChanged(); |
19 | 29 | } |
20 | 30 | } |
21 | 31 |
|
22 | | - const synclet1 = new Synclet(new TestValueConnector(), new MemoryTransport()); |
23 | | - const synclet2 = new Synclet(new TestValueConnector(), new MemoryTransport()); |
| 32 | + const connector1 = new TestValueConnector(); |
| 33 | + const connector2 = new TestValueConnector(); |
24 | 34 |
|
25 | | - expect(synclet1.getConnector().getUnderlyingValue()).toEqual( |
26 | | - synclet2.getConnector().getUnderlyingValue(), |
| 35 | + const synclet1 = new Synclet(connector1, new MemoryTransport()); |
| 36 | + await synclet1.start(); |
| 37 | + |
| 38 | + const synclet2 = new Synclet(connector2, new MemoryTransport()); |
| 39 | + await synclet2.start(); |
| 40 | + |
| 41 | + expect(connector1.getUnderlyingValue()).toEqual( |
| 42 | + connector2.getUnderlyingValue(), |
27 | 43 | ); |
| 44 | + |
| 45 | + await connector1.setUnderlyingValue('V2'); |
| 46 | + expect(connector2.getUnderlyingValue()).toEqual('V2'); |
28 | 47 | }); |
0 commit comments