diff --git a/test/graph.test.ts b/test/graph.test.ts index 4e270b6..787884e 100644 --- a/test/graph.test.ts +++ b/test/graph.test.ts @@ -1,12 +1,30 @@ -import { FileGraph } from 'lib'; import assert from 'node:assert'; +import { describe, it } from 'node:test'; +import { FileGraph } from 'lib'; -import test from 'node:test'; const graph = FileGraph('./data.txt'); -test('create Vertex and findOne', async t => { - const model = { name: 'Dyor', age: new Date().toString() }; - const id = await graph.createVertex(model); - const finModel = await graph.findOne(model => model.id == id); - console.log(finModel); - assert.deepStrictEqual({ id, ...model }, finModel); +const myVertex = { name: 'Diy0r', age: new Date().toString() }; +let globId = '6c5febc1-161b-46c7-abf6-b20088fd410e'; +describe('CRUD', t => { + it('create Vertex and findOne', async t => { + const createdVertexId = await graph.createVertex(myVertex); + const findVertex = await graph.findOne( + vertex => vertex.id == createdVertexId, + ); + assert.deepStrictEqual({ id: createdVertexId, ...myVertex }, findVertex); + globId = findVertex.id; + }); + it('update Vertex', async t => { + const isUpdate = await graph.updateVertex(model => + model.id == globId ? { name: 'Dupo', id: '121212', sdsds: 'sdsd' } : null, + ); + assert.equal(isUpdate, true); + }); + + it('check updated vertex name', async t => { + const findVertex = await graph.findOne( + vertex => vertex.id == globId, + ); + assert.deepStrictEqual(findVertex.name, 'Dupo'); + }); });