From 34a157c6094e332d4ad16518386b87857aecdee9 Mon Sep 17 00:00:00 2001 From: Mark Krasner Date: Wed, 11 Dec 2024 11:07:20 -0500 Subject: [PATCH] Restructuring listType integration test --- .../test/model-mid-listType.test.ts | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/tests/c1-integration/test/model-mid-listType.test.ts b/tests/c1-integration/test/model-mid-listType.test.ts index e46bb17..c3d7357 100644 --- a/tests/c1-integration/test/model-mid-listType.test.ts +++ b/tests/c1-integration/test/model-mid-listType.test.ts @@ -1,4 +1,5 @@ import { CeramicClient } from '@ceramic-sdk/http-client' +import type { CommitID, StreamID } from '@ceramic-sdk/identifiers' import { ModelClient } from '@ceramic-sdk/model-client' import { ModelInstanceClient } from '@ceramic-sdk/model-instance-client' import type { ModelDefinition } from '@ceramic-sdk/model-protocol' @@ -30,50 +31,56 @@ const CONTAINER_OPTS: EnvironmentOptions = { testPort: 5223, } -describe('model integration test', () => { +const client = new CeramicClient({ + url: `http://127.0.0.1:${CONTAINER_OPTS.apiPort}`, +}) + +const modelInstanceClient = new ModelInstanceClient({ + ceramic: client, + did: authenticatedDID, +}) + +const modelClient = new ModelClient({ + ceramic: client, + did: authenticatedDID, +}) + +describe('model integration test for list model and MID', () => { let c1Container: CeramicOneContainer - const client = new CeramicClient({ - url: `http://127.0.0.1:${CONTAINER_OPTS.apiPort}`, - }) + let modelStream: StreamID + let documentStream: CommitID beforeAll(async () => { c1Container = await CeramicOneContainer.startContainer(CONTAINER_OPTS) + modelStream = await modelClient.postDefinition(testModel) }, 10000) - test('create LIST model, model instance, and updates to instance using the model', async () => { - const modelInstanceClient = new ModelInstanceClient({ - ceramic: client, - did: authenticatedDID, - }) - const modelClient = new ModelClient({ - ceramic: client, - did: authenticatedDID, - }) - const modelStream = await modelClient.postDefinition(testModel) + test('gets correct model definition', async () => { + // wait one second + await new Promise((resolve) => setTimeout(resolve, 1000)) const definition = await modelClient.getModelDefinition(modelStream) expect(definition).toEqual(testModel) - - const documentStream = await modelInstanceClient.postSignedInit({ + }) + test('posts signed init event and obtains correct state', async () => { + documentStream = await modelInstanceClient.postSignedInit({ model: modelStream, content: { test: 'hello' }, shouldIndex: true, }) - // wait 1 seconds await new Promise((resolve) => setTimeout(resolve, 1000)) const currentState = await modelInstanceClient.getDocumentState( documentStream.toString(), ) - - // wait 1 seconds - await new Promise((resolve) => setTimeout(resolve, 1000)) + expect(currentState.content).toEqual({ test: 'hello' }) + }) + test('updates document and obtains correct state', async () => { // update the document const updatedState = await modelInstanceClient.updateDocument({ streamID: documentStream.toString(), newContent: { test: 'world' }, shouldIndex: true, }) - expect(currentState.content).toEqual({ test: 'hello' }) expect(updatedState.content).toEqual({ test: 'world' }) }) afterAll(async () => {