From 57c36b390091b1079821cfcb4522cdf5469e3f20 Mon Sep 17 00:00:00 2001 From: lana-k Date: Sat, 7 Feb 2026 22:08:39 +0100 Subject: [PATCH] tests for migration --- tests/lib/storedInquiries/_migrations.spec.js | 97 +++++++ .../storedInquiries/storedInquiries.spec.js | 251 +++++++++++++++++- 2 files changed, 335 insertions(+), 13 deletions(-) diff --git a/tests/lib/storedInquiries/_migrations.spec.js b/tests/lib/storedInquiries/_migrations.spec.js index 1b0419d..9a2f53e 100644 --- a/tests/lib/storedInquiries/_migrations.spec.js +++ b/tests/lib/storedInquiries/_migrations.spec.js @@ -39,4 +39,101 @@ describe('_migrations.js', () => { } ]) }) + + it('migrates from version 2 to the current', () => { + const oldInquiries = [ + { + id: '123', + name: 'foo', + query: 'SELECT * FROM foo', + viewType: 'chart', + viewOptions: { here_are: 'foo chart settings' }, + createdAt: '2021-05-06T11:05:50.877Z' + }, + { + id: '456', + name: 'bar', + query: 'SELECT * FROM bar', + viewType: 'graph', + viewOptions: { + structure: { + nodeId: 'node_id', + objectType: 'object_type', + edgeSource: 'source', + edgeTarget: 'target' + }, + style: { + backgroundColor: 'white', + nodes: { + size: { type: 'constant', value: 10 }, + color: { + type: 'calculated', + method: 'degree', + colorscale: null, + mode: 'continious', + colorscaleDirection: 'reversed' + }, + label: { source: 'label', color: '#444444' } + }, + edges: { + showDirection: true, + size: { type: 'constant', value: 2 }, + color: { type: 'constant', value: '#a2b1c6' }, + label: { source: null, color: '#a2b1c6' } + } + }, + layout: { type: 'circular', options: null } + }, + createdAt: '2021-05-07T11:05:50.877Z' + } + ] + expect(migrations._migrate(2, oldInquiries)).to.eql([ + { + id: '123', + name: 'foo', + query: 'SELECT * FROM foo', + viewType: 'chart', + viewOptions: { here_are: 'foo chart settings' }, + createdAt: '2021-05-06T11:05:50.877Z' + }, + { + id: '456', + name: 'bar', + query: 'SELECT * FROM bar', + viewType: 'graph', + viewOptions: { + structure: { + nodeId: 'node_id', + objectType: 'object_type', + edgeSource: 'source', + edgeTarget: 'target' + }, + style: { + backgroundColor: 'white', + highlightMode: 'node_and_neighbors', + nodes: { + size: { type: 'constant', value: 10 }, + color: { + type: 'calculated', + method: 'degree', + colorscale: null, + mode: 'continious', + colorscaleDirection: 'reversed', + opacity: 100 + }, + label: { source: 'label', color: '#444444' } + }, + edges: { + showDirection: true, + size: { type: 'constant', value: 2 }, + color: { type: 'constant', value: '#a2b1c6' }, + label: { source: null, color: '#a2b1c6' } + } + }, + layout: { type: 'circular', options: null } + }, + createdAt: '2021-05-07T11:05:50.877Z' + } + ]) + }) }) diff --git a/tests/lib/storedInquiries/storedInquiries.spec.js b/tests/lib/storedInquiries/storedInquiries.spec.js index e62c698..5b3079e 100644 --- a/tests/lib/storedInquiries/storedInquiries.spec.js +++ b/tests/lib/storedInquiries/storedInquiries.spec.js @@ -125,6 +125,7 @@ describe('storedInquiries.js', () => { }, style: { backgroundColor: 'white', + highlightMode: 'node_and_neighbors', nodes: { size: { type: 'constant', value: 10 }, color: { @@ -256,7 +257,7 @@ describe('storedInquiries.js', () => { }) }) - it('deserialiseInquiries migrates inquiries', () => { + it('deserialiseInquiries migrates inquiries of v1', () => { const str = `[ { "id": 1, @@ -295,7 +296,110 @@ describe('storedInquiries.js', () => { ]) }) - it('deserialiseInquiries return array for one inquiry of v1', () => { + it('deserialiseInquiries migrates inquiries of v2', () => { + const str = `{ + "version": 2, + "inquiries": [ + { + "id": 1, + "name": "foo", + "query": "select * from foo", + "viewType": "chart", + "viewOptions": [], + "createdAt": "2020-11-03T14:17:49.524Z" + }, + { + "id": "Xh1Hc9v7P3mRPZVM59QiC", + "query": "SELECT * from doc", + "viewType": "graph", + "viewOptions": { + "structure": { + "nodeId": "node_id", + "objectType": "object_type", + "edgeSource": "source", + "edgeTarget": "target" + }, + "style": { + "backgroundColor": "white", + "nodes": { + "size": { "type": "constant", "value": 10 }, + "color": { + "type": "calculated", + "method": "degree", + "colorscale": null, + "mode": "continious", + "colorscaleDirection": "reversed" + }, + "label": { "source": "label", "color": "#444444" } + }, + "edges": { + "showDirection": true, + "size": { "type": "constant", "value": 2 }, + "color": { "type": "constant", "value": "#a2b1c6" }, + "label": { "source": null, "color": "#a2b1c6" } + } + }, + "layout": { "type": "circular", "options": null } + }, + "name": "student graph", + "createdAt": "2026-01-19T21:46:13.899Z" + } + ] + } + ` + + const inquiry = storedInquiries.deserialiseInquiries(str) + expect(inquiry).to.eql([ + { + id: 1, + name: 'foo', + query: 'select * from foo', + viewType: 'chart', + viewOptions: [], + createdAt: '2020-11-03T14:17:49.524Z' + }, + { + id: 'Xh1Hc9v7P3mRPZVM59QiC', + query: 'SELECT * from doc', + viewType: 'graph', + viewOptions: { + structure: { + nodeId: 'node_id', + objectType: 'object_type', + edgeSource: 'source', + edgeTarget: 'target' + }, + style: { + backgroundColor: 'white', + highlightMode: 'node_and_neighbors', + nodes: { + size: { type: 'constant', value: 10 }, + color: { + type: 'calculated', + method: 'degree', + colorscale: null, + mode: 'continious', + colorscaleDirection: 'reversed', + opacity: 100 + }, + label: { source: 'label', color: '#444444' } + }, + edges: { + showDirection: true, + size: { type: 'constant', value: 2 }, + color: { type: 'constant', value: '#a2b1c6' }, + label: { source: null, color: '#a2b1c6' } + } + }, + layout: { type: 'circular', options: null } + }, + name: 'student graph', + createdAt: '2026-01-19T21:46:13.899Z' + } + ]) + }) + + it('deserialiseInquiries returns array for one inquiry of v1', () => { const str = ` { "id": 1, @@ -407,7 +511,7 @@ describe('storedInquiries.js', () => { ]) }) - it('readPredefinedInquiries old', async () => { + it('readPredefinedInquiries v1', async () => { const str = `[ { "id": 1, @@ -432,18 +536,55 @@ describe('storedInquiries.js', () => { ]) }) - it('readPredefinedInquiries', async () => { + it('readPredefinedInquiries v2', async () => { const str = `{ - "version": 3, + "version": 2, "inquiries": [ - { - "id": 1, - "name": "foo", - "query": "select * from foo", - "viewType": "chart", - "viewOptions": [], - "createdAt": "2020-11-03T14:17:49.524Z" - }] + { + "id": 1, + "name": "foo", + "query": "select * from foo", + "viewType": "chart", + "viewOptions": [], + "createdAt": "2020-11-03T14:17:49.524Z" + }, + { + "id": "Xh1Hc9v7P3mRPZVM59QiC", + "query": "SELECT * from doc", + "viewType": "graph", + "viewOptions": { + "structure": { + "nodeId": "node_id", + "objectType": "object_type", + "edgeSource": "source", + "edgeTarget": "target" + }, + "style": { + "backgroundColor": "white", + "nodes": { + "size": { "type": "constant", "value": 10 }, + "color": { + "type": "calculated", + "method": "degree", + "colorscale": null, + "mode": "continious", + "colorscaleDirection": "reversed" + }, + "label": { "source": "label", "color": "#444444" } + }, + "edges": { + "showDirection": true, + "size": { "type": "constant", "value": 2 }, + "color": { "type": "constant", "value": "#a2b1c6" }, + "label": { "source": null, "color": "#a2b1c6" } + } + }, + "layout": { "type": "circular", "options": null } + }, + "name": "student graph", + "createdAt": "2026-01-19T21:46:13.899Z" + } + ] } ` sinon.stub(fu, 'readFile').returns(Promise.resolve(new Response(str))) @@ -457,6 +598,90 @@ describe('storedInquiries.js', () => { viewType: 'chart', viewOptions: [], createdAt: '2020-11-03T14:17:49.524Z' + }, + { + id: 'Xh1Hc9v7P3mRPZVM59QiC', + query: 'SELECT * from doc', + viewType: 'graph', + viewOptions: { + structure: { + nodeId: 'node_id', + objectType: 'object_type', + edgeSource: 'source', + edgeTarget: 'target' + }, + style: { + backgroundColor: 'white', + highlightMode: 'node_and_neighbors', + nodes: { + size: { type: 'constant', value: 10 }, + color: { + type: 'calculated', + method: 'degree', + colorscale: null, + mode: 'continious', + colorscaleDirection: 'reversed', + opacity: 100 + }, + label: { source: 'label', color: '#444444' } + }, + edges: { + showDirection: true, + size: { type: 'constant', value: 2 }, + color: { type: 'constant', value: '#a2b1c6' }, + label: { source: null, color: '#a2b1c6' } + } + }, + layout: { type: 'circular', options: null } + }, + name: 'student graph', + createdAt: '2026-01-19T21:46:13.899Z' + } + ]) + }) + + it('readPredefinedInquiries', async () => { + const str = `{ + "version": 3, + "inquiries": [ + { + "id": 1, + "name": "foo", + "query": "select * from foo", + "viewType": "chart", + "viewOptions": [], + "createdAt": "2020-11-03T14:17:49.524Z" + }, + { + "id": 2, + "name": "boo", + "query": "select * from boo", + "viewType": "graph", + "viewOptions": {}, + "createdAt": "2020-11-03T14:17:49.524Z" + } + ] + } + ` + sinon.stub(fu, 'readFile').returns(Promise.resolve(new Response(str))) + const inquiries = await storedInquiries.readPredefinedInquiries() + expect(fu.readFile.calledOnceWith('./inquiries.json')).to.equal(true) + expect(inquiries).to.eql([ + { + id: 1, + name: 'foo', + query: 'select * from foo', + viewType: 'chart', + viewOptions: [], + createdAt: '2020-11-03T14:17:49.524Z' + }, + { + id: 2, + name: 'boo', + query: 'select * from boo', + viewType: 'graph', + viewOptions: {}, + createdAt: '2020-11-03T14:17:49.524Z' } ]) })