From 0390ca311953eb8d39dd0dba7627a4c9c1c752a9 Mon Sep 17 00:00:00 2001 From: diy0r Date: Fri, 9 Aug 2024 00:30:28 +0500 Subject: [PATCH] test: check updated vertex --- test/graph.test.ts | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) 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'); + }); });