|
| 1 | +import type { DataStore, EventLog, MessageStore } from '../src/index.js'; |
1 | 2 | import type { EventsGetReply, RecordsWriteMessage, TenantGate } from '../src/index.js'; |
2 | 3 |
|
3 | 4 | import chaiAsPromised from 'chai-as-promised'; |
4 | 5 | import sinon from 'sinon'; |
5 | 6 | import chai, { expect } from 'chai'; |
6 | 7 |
|
7 | | -import { DataStoreLevel } from '../src/store/data-store-level.js'; |
8 | 8 | import { DidKeyResolver } from '../src/did/did-key-resolver.js'; |
9 | 9 | import { Dwn } from '../src/dwn.js'; |
10 | 10 | import { Encoder } from '../src/index.js'; |
11 | | -import { EventLogLevel } from '../src/event-log/event-log-level.js'; |
12 | | -import { MessageStoreLevel } from '../src/store/message-store-level.js'; |
| 11 | +import { stubInterface } from 'ts-sinon'; |
13 | 12 | import { TestDataGenerator } from './utils/test-data-generator.js'; |
| 13 | +import { TestStoreInitializer } from './test-store-initializer.js'; |
14 | 14 | import { DwnInterfaceName, DwnMethodName, Message } from '../src/core/message.js'; |
15 | 15 | import { Jws, RecordsRead } from '../src/index.js'; |
16 | 16 |
|
17 | 17 | chai.use(chaiAsPromised); |
18 | 18 |
|
19 | 19 | describe('DWN', () => { |
20 | | - let messageStore: MessageStoreLevel; |
21 | | - let dataStore: DataStoreLevel; |
22 | | - let eventLog: EventLogLevel; |
| 20 | + let messageStore: MessageStore; |
| 21 | + let dataStore: DataStore; |
| 22 | + let eventLog: EventLog; |
23 | 23 | let dwn: Dwn; |
24 | 24 |
|
| 25 | + // important to follow the `before` and `after` pattern to initialize and clean the stores in tests |
| 26 | + // so that different test suites can reuse the same backend store for testing |
25 | 27 | before(async () => { |
26 | | - // important to follow this pattern to initialize the message store in tests |
27 | | - // so that different suites can reuse the same block store and index location for testing |
28 | | - messageStore = new MessageStoreLevel({ |
29 | | - blockstoreLocation : 'TEST-MESSAGESTORE', |
30 | | - indexLocation : 'TEST-INDEX' |
31 | | - }); |
32 | | - |
33 | | - dataStore = new DataStoreLevel({ |
34 | | - blockstoreLocation: 'TEST-DATASTORE' |
35 | | - }); |
36 | | - |
37 | | - eventLog = new EventLogLevel({ |
38 | | - location: 'TEST-EVENTLOG' |
39 | | - }); |
| 28 | + const stores = TestStoreInitializer.initializeStores(); |
| 29 | + messageStore = stores.messageStore; |
| 30 | + dataStore = stores.dataStore; |
| 31 | + eventLog = stores.eventLog; |
40 | 32 |
|
41 | 33 | dwn = await Dwn.create({ messageStore, dataStore, eventLog }); |
42 | 34 | }); |
@@ -144,9 +136,9 @@ describe('DWN', () => { |
144 | 136 | } |
145 | 137 | }; |
146 | 138 |
|
147 | | - const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); |
148 | | - const dataStoreStub = sinon.createStubInstance(DataStoreLevel); |
149 | | - const eventLogStub = sinon.createStubInstance(EventLogLevel); |
| 139 | + const messageStoreStub = stubInterface<MessageStore>(); |
| 140 | + const dataStoreStub = stubInterface<DataStore>(); |
| 141 | + const eventLogStub = stubInterface<EventLog>(); |
150 | 142 |
|
151 | 143 | const dwnWithConfig = await Dwn.create({ |
152 | 144 | tenantGate : blockAllTenantGate, |
@@ -285,9 +277,9 @@ describe('DWN', () => { |
285 | 277 | } |
286 | 278 | }; |
287 | 279 |
|
288 | | - const messageStoreStub = sinon.createStubInstance(MessageStoreLevel); |
289 | | - const dataStoreStub = sinon.createStubInstance(DataStoreLevel); |
290 | | - const eventLogStub = sinon.createStubInstance(EventLogLevel); |
| 280 | + const messageStoreStub = stubInterface<MessageStore>(); |
| 281 | + const dataStoreStub = stubInterface<DataStore>(); |
| 282 | + const eventLogStub = stubInterface<EventLog>(); |
291 | 283 |
|
292 | 284 | const dwnWithConfig = await Dwn.create({ |
293 | 285 | tenantGate : blockAllTenantGate, |
|
0 commit comments