fix: test case

This commit is contained in:
DarkSky
2024-08-24 02:18:23 +08:00
parent 1e1a9552c0
commit c28ef3189c
5 changed files with 18 additions and 18 deletions
@@ -46,10 +46,10 @@ export class PgUserspaceDocStorageAdapter extends DocStorageAdapter {
}
async pushDocUpdates(
editorId: string,
userId: string,
docId: string,
updates: Uint8Array[]
updates: Uint8Array[],
editorId?: string
) {
if (!updates.length) {
return 0;
@@ -36,10 +36,10 @@ export class PgWorkspaceDocStorageAdapter extends DocStorageAdapter {
}
async pushDocUpdates(
editorId: string,
workspaceId: string,
docId: string,
updates: Uint8Array[]
updates: Uint8Array[],
editorId?: string
) {
if (!updates.length) {
return 0;
@@ -270,7 +270,7 @@ export class PgWorkspaceDocStorageAdapter extends DocStorageAdapter {
}
override async rollbackDoc(
editorId: string,
editorId: string | undefined,
spaceId: string,
docId: string,
timestamp: number
@@ -97,10 +97,10 @@ export abstract class DocStorageAdapter extends Connection {
}
abstract pushDocUpdates(
editorId: string,
spaceId: string,
docId: string,
updates: Uint8Array[]
updates: Uint8Array[],
editorId?: string
): Promise<number>;
abstract deleteDoc(spaceId: string, docId: string): Promise<void>;
@@ -124,7 +124,7 @@ export abstract class DocStorageAdapter extends Connection {
}
const change = this.generateChangeUpdate(fromSnapshot.bin, toSnapshot.bin);
await this.pushDocUpdates(editorId, spaceId, docId, [change]);
await this.pushDocUpdates(spaceId, docId, [change], editorId);
// force create a new history record after rollback
await this.createDocHistory(fromSnapshot, true);
}
@@ -277,10 +277,10 @@ export class SpaceSyncGateway
// TODO(@forehalo): we might need to check write permission before push updates
const timestamp = await adapter.push(
user.id,
spaceId,
docId,
updates.map(update => Buffer.from(update, 'base64'))
updates.map(update => Buffer.from(update, 'base64')),
user.id
);
// could be put in [adapter.push]
@@ -601,9 +601,9 @@ abstract class SyncSocketAdapter {
permission?: Permission
): Promise<void>;
push(editorId: string, spaceId: string, docId: string, updates: Buffer[]) {
push(spaceId: string, docId: string, updates: Buffer[], editorId: string) {
this.assertIn(spaceId);
return this.storage.pushDocUpdates(editorId, spaceId, docId, updates);
return this.storage.pushDocUpdates(spaceId, docId, updates, editorId);
}
get(spaceId: string, docId: string) {
@@ -627,13 +627,13 @@ class WorkspaceSyncAdapter extends SyncSocketAdapter {
}
override push(
editorId: string,
spaceId: string,
docId: string,
updates: Buffer[]
updates: Buffer[],
editorId: string
) {
const id = new DocID(docId, spaceId);
return super.push(editorId, spaceId, id.guid, updates);
return super.push(spaceId, id.guid, updates, editorId);
}
override get(spaceId: string, docId: string) {
@@ -1,5 +1,3 @@
import { randomUUID } from 'node:crypto';
import { TestingModule } from '@nestjs/testing';
import type { Snapshot } from '@prisma/client';
import { PrismaClient } from '@prisma/client';
@@ -50,6 +48,8 @@ const snapshot: Snapshot = {
seq: 0,
updatedAt: new Date(),
createdAt: new Date(),
createdBy: null,
updatedBy: null,
};
function getSnapshot(timestamp: number = Date.now()): DocRecord {
@@ -264,7 +264,7 @@ test('should be able to recover from history', async t => {
await adapter.createDocHistory(getSnapshot(history1Timestamp));
await adapter.rollbackDoc(
randomUUID(),
undefined,
snapshot.workspaceId,
snapshot.id,
history1Timestamp