mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-31 12:23:40 +00:00
move client from separate repo
This commit is contained in:
26
client/tests/mocks/bootstrapper.mock.ts
Normal file
26
client/tests/mocks/bootstrapper.mock.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Bootstrapper, DBCache } from '../../lib/patch-db'
|
||||
|
||||
export class MockBootstrapper<T> implements Bootstrapper<T> {
|
||||
|
||||
constructor (
|
||||
private sequence: number = 0,
|
||||
private data: T = { } as T,
|
||||
) { }
|
||||
|
||||
async init (): Promise<DBCache<T>> {
|
||||
return {
|
||||
sequence: this.sequence,
|
||||
data: this.data as T,
|
||||
}
|
||||
}
|
||||
|
||||
async update (cache: DBCache<T>): Promise<void> {
|
||||
this.sequence = cache.sequence
|
||||
this.data = cache.data
|
||||
}
|
||||
|
||||
async clear (): Promise<void> {
|
||||
this.sequence = 0
|
||||
this.data = { } as T
|
||||
}
|
||||
}
|
||||
17
client/tests/mocks/http.mock.ts
Normal file
17
client/tests/mocks/http.mock.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Http } from '../../lib/patch-db'
|
||||
import { Revision, Dump } from '../../lib/sequence-store'
|
||||
|
||||
export class MockHttp<T> implements Http<T> {
|
||||
constructor (private readonly mockData: {
|
||||
getSequences: Revision[],
|
||||
getDump: Dump<T>
|
||||
}) { }
|
||||
|
||||
getRevisions (): Promise<Revision[]> {
|
||||
return Promise.resolve(this.mockData.getSequences)
|
||||
}
|
||||
|
||||
getDump (): Promise<Dump<T>> {
|
||||
return Promise.resolve(this.mockData.getDump)
|
||||
}
|
||||
}
|
||||
1
client/tests/mocks/mock-data.json
Normal file
1
client/tests/mocks/mock-data.json
Normal file
File diff suppressed because one or more lines are too long
18
client/tests/mocks/source.mock.ts
Normal file
18
client/tests/mocks/source.mock.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Observable } from 'rxjs'
|
||||
import { UpdateReal } from '../../lib/sequence-store'
|
||||
import { Source } from '../../lib/source/source'
|
||||
|
||||
export class MockSource<T> implements Source<T> {
|
||||
|
||||
constructor (
|
||||
private readonly mockData: Observable<UpdateReal<T>>,
|
||||
) { }
|
||||
|
||||
watch$ (): Observable<UpdateReal<T>> {
|
||||
return this.mockData
|
||||
}
|
||||
|
||||
start (): void { }
|
||||
|
||||
stop (): void { }
|
||||
}
|
||||
Reference in New Issue
Block a user