| 1104 | }) |
| 1105 | |
| 1106 | async function makeTestInstance() { |
| 1107 | const server = new TestServer(bookSchema) |
| 1108 | const socketPair = new TestSocketPair('test', server) |
| 1109 | socketPair.connect() |
| 1110 | |
| 1111 | const flush = async () => { |
| 1112 | await Promise.resolve() |
| 1113 | while (socketPair.getNeedsFlushing()) { |
| 1114 | socketPair.flushClientSentEvents() |
| 1115 | socketPair.flushServerSentEvents() |
| 1116 | } |
| 1117 | } |
| 1118 | let onSyncError = vi.fn() |
| 1119 | const client = await new Promise<TLSyncClient<Book | Presence>>((resolve, reject) => { |
| 1120 | onSyncError = vi.fn(reject) |
| 1121 | const client = new TLSyncClient({ |
| 1122 | store: new Store<Book | Presence, unknown>({ |
| 1123 | schema: bookSchemaWithoutValidator, |
| 1124 | props: {}, |
| 1125 | }), |
| 1126 | socket: socketPair.clientSocket as any, |
| 1127 | onLoad: resolve, |
| 1128 | onSyncError, |
| 1129 | presence: computed('', () => null), |
| 1130 | }) |
| 1131 | disposables.push(() => client.close()) |
| 1132 | flush() |
| 1133 | }) |
| 1134 | |
| 1135 | return { |
| 1136 | server, |
| 1137 | socketPair, |
| 1138 | client, |
| 1139 | flush, |
| 1140 | onSyncError, |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | it('[RP2] rejects invalid put operations that create a new document', async () => { |
| 1145 | const { client, flush, onSyncError, server } = await makeTestInstance() |