From e89beb3e8e0609b2f7ac1554c1f0652ebbb76cd0 Mon Sep 17 00:00:00 2001 From: Moises Sacal <moisbo@gmail.com> Date: Wed, 29 May 2019 11:43:08 +1000 Subject: [PATCH] Added farm to freeways test: --- .idea/workspace.xml | 78 +++++++++++++++----------------------------- test/catalog.spec.js | 40 +++++++++++++++++++++-- 2 files changed, 65 insertions(+), 53 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9c85f04..a67af72 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,18 +2,6 @@ <project version="4"> <component name="ChangeListManager"> <list default="true" id="ad75bb9b-12db-4cad-af64-4c68cecdb87b" name="Default Changelist" comment=""> - <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/lib/CatalogSolr.js" beforeDir="false" afterPath="$PROJECT_DIR$/lib/CatalogSolr.js" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/test-data/datacrates/0e83bc52-1887-4c75-ac5d-a15e74858a10/CATALOG.json" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/test-data/datacrates/1c4b4b88-28ed-4cc8-9f55-7c3a93941a7f/CATALOG.json" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/test-data/datacrates/3c26a97b-2960-4704-8071-6fcf648e2cff/CATALOG.json" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/test-data/datacrates/5aed364c-3459-485c-99fa-2526719227a6/CATALOG.json" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/test-data/datacrates/8019258e-e826-4387-bac0-7730bc333514/CATALOG.json" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/test-data/datacrates/82d1b263-2beb-443a-85b5-8b9018137991/CATALOG.json" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/test-data/datacrates/cefdbe3d-f3f7-49bd-97a5-6575549c2d1c/CATALOG.json" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/test-data/datacrates/dc1b4d81-4c48-439a-a329-39cb10a28e0f/CATALOG.json" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/test-data/datacrates/f3e568cf-42a9-42b6-8217-e697457dab8c/CATALOG.json" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/test-data/fields.json" beforeDir="false" afterPath="$PROJECT_DIR$/test-data/fields.json" afterDir="false" /> <change beforePath="$PROJECT_DIR$/test/catalog.spec.js" beforeDir="false" afterPath="$PROJECT_DIR$/test/catalog.spec.js" afterDir="false" /> </list> <ignored path="$PROJECT_DIR$/.tmp/" /> @@ -32,8 +20,8 @@ <file pinned="false" current-in-tab="true"> <entry file="file://$PROJECT_DIR$/test/catalog.spec.js"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="555"> - <caret line="129" column="64" selection-start-line="129" selection-start-column="64" selection-end-line="129" selection-end-column="64" /> + <state relative-caret-position="269"> + <caret line="137" column="63" selection-start-line="137" selection-start-column="63" selection-end-line="137" selection-end-column="63" /> </state> </provider> </entry> @@ -81,7 +69,7 @@ <file pinned="false" current-in-tab="true"> <entry file="file://$PROJECT_DIR$/test-data/fields.json"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="291"> + <state relative-caret-position="678"> <caret line="46" column="4" selection-start-line="46" selection-start-column="4" selection-end-line="46" selection-end-column="4" /> </state> </provider> @@ -128,17 +116,17 @@ <option value="$PROJECT_DIR$/test-data/FARMTOFREEWAYS_CATALOG.json" /> <option value="$APPLICATION_CONFIG_DIR$/scratches/scratch_3.js" /> <option value="$PROJECT_DIR$/test-data/CatalogSolr.json" /> - <option value="$PROJECT_DIR$/.gitignore" /> <option value="$PROJECT_DIR$/lib/CatalogSolr.js" /> <option value="$PROJECT_DIR$/test-data/fields.json" /> + <option value="$PROJECT_DIR$/.gitignore" /> <option value="$PROJECT_DIR$/test/catalog.spec.js" /> </list> </option> </component> <component name="ProjectFrameBounds" extendedState="6"> - <option name="x" value="1440" /> + <option name="x" value="1442" /> <option name="y" value="-277" /> - <option name="width" value="1920" /> + <option name="width" value="1918" /> <option name="height" value="1177" /> </component> <component name="ProjectLevelVcsManager" settingsEditedManually="true" /> @@ -233,17 +221,11 @@ <option name="presentableId" value="Default" /> <updated>1558421147646</updated> <workItem from="1558421149207" duration="30478000" /> - <workItem from="1558654598476" duration="36666000" /> + <workItem from="1558654598476" duration="36874000" /> </task> <servers /> </component> <component name="TestHistory"> - <history-entry file="catalog_spec_js - 2019.05.29 at 11h 22m 07s.xml"> - <configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" /> - </history-entry> - <history-entry file="catalog_spec_js - 2019.05.29 at 11h 22m 47s.xml"> - <configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" /> - </history-entry> <history-entry file="catalog_spec_js - 2019.05.29 at 11h 24m 46s.xml"> <configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" /> </history-entry> @@ -268,27 +250,33 @@ <history-entry file="catalog_spec_js - 2019.05.29 at 11h 32m 46s.xml"> <configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" /> </history-entry> + <history-entry file="catalog_spec_js - 2019.05.29 at 11h 33m 20s.xml"> + <configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" /> + </history-entry> + <history-entry file="catalog_spec_js - 2019.05.29 at 11h 33m 21s.xml"> + <configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" /> + </history-entry> </component> <component name="TimeTrackingManager"> - <option name="totallyTimeSpent" value="67144000" /> + <option name="totallyTimeSpent" value="67352000" /> </component> <component name="ToolWindowManager"> <frame x="1440" y="-277" width="1920" height="1177" extended-state="6" /> <editor active="true" /> <layout> - <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.15481833" /> + <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.15481833" /> <window_info id="Structure" order="1" side_tool="true" weight="0.25" /> <window_info id="Favorites" order="2" side_tool="true" /> <window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Find" order="1" /> <window_info anchor="bottom" id="Run" order="2" weight="0.3299539" /> - <window_info active="true" anchor="bottom" id="Debug" order="3" visible="true" weight="0.35668203" /> + <window_info anchor="bottom" id="Debug" order="3" weight="0.35668203" /> <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="TODO" order="6" /> <window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" /> <window_info anchor="bottom" id="Version Control" order="8" /> - <window_info anchor="bottom" id="Terminal" order="9" weight="0.23870967" /> + <window_info anchor="bottom" id="Terminal" order="9" visible="true" weight="0.23870967" /> <window_info anchor="bottom" id="Event Log" order="10" side_tool="true" /> <window_info anchor="right" id="Commander" order="0" weight="0.4" /> <window_info anchor="right" id="Ant Build" order="1" weight="0.25" /> @@ -298,18 +286,6 @@ <component name="TypeScriptGeneratedFilesManager"> <option name="version" value="1" /> </component> - <component name="XDebuggerManager"> - <breakpoint-manager> - <breakpoints> - <line-breakpoint enabled="true" type="javascript"> - <url>file://$PROJECT_DIR$/test/catalog.spec.js</url> - <line>128</line> - <properties lambdaOrdinal="-1" /> - <option name="timeStamp" value="95" /> - </line-breakpoint> - </breakpoints> - </breakpoint-manager> - </component> <component name="editorHistoryManager"> <entry file="file://$PROJECT_DIR$/test-data/datacrates/c1517eee-9bef-4d05-912c-6b73413718c7/CATALOG.json" /> <entry file="file://$PROJECT_DIR$/test-data/datacrates/4b4bc2b5-4a13-4369-be01-45ddceb440f3/CATALOG.json" /> @@ -330,13 +306,6 @@ </state> </provider> </entry> - <entry file="file://$PROJECT_DIR$/.gitignore"> - <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="15"> - <caret line="1" column="12" selection-start-line="1" selection-start-column="12" selection-end-line="1" selection-end-column="12" /> - </state> - </provider> - </entry> <entry file="file://$PROJECT_DIR$/test-data/FARMTOFREEWAYS_CATALOG.json"> <provider selected="true" editor-type-id="text-editor"> <state relative-caret-position="300"> @@ -360,7 +329,7 @@ </entry> <entry file="file://$PROJECT_DIR$/test-data/fields.json"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="291"> + <state relative-caret-position="678"> <caret line="46" column="4" selection-start-line="46" selection-start-column="4" selection-end-line="46" selection-end-column="4" /> </state> </provider> @@ -372,10 +341,17 @@ </state> </provider> </entry> + <entry file="file://$PROJECT_DIR$/.gitignore"> + <provider selected="true" editor-type-id="text-editor"> + <state relative-caret-position="30"> + <caret line="2" column="21" lean-forward="true" selection-start-line="2" selection-start-column="21" selection-end-line="2" selection-end-column="21" /> + </state> + </provider> + </entry> <entry file="file://$PROJECT_DIR$/test/catalog.spec.js"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="555"> - <caret line="129" column="64" selection-start-line="129" selection-start-column="64" selection-end-line="129" selection-end-column="64" /> + <state relative-caret-position="269"> + <caret line="137" column="63" selection-start-line="137" selection-start-column="63" selection-end-line="137" selection-end-column="63" /> </state> </provider> </entry> diff --git a/test/catalog.spec.js b/test/catalog.spec.js index 0c93ef0..11ce747 100644 --- a/test/catalog.spec.js +++ b/test/catalog.spec.js @@ -81,7 +81,7 @@ describe('catalog', function () { const fieldConfig = catalog.config; - //TODO: Peter's idea is to convert everything into an array then it is safer to work to convert + //Peter's idea is to convert everything into an array then it is safer to work to convert const graph = _.each(ca['@graph'], (g) => { return catalog.ensureObjArray(g); }); @@ -104,7 +104,43 @@ describe('catalog', function () { const fieldConfig = catalog.config; - //TODO: Peter's idea is to convert everything into an array then it is safer to work to convert + //Peter's idea is to convert everything into an array then it is safer to work to convert + const graph = _.each(ca['@graph'], (g) => { + return catalog.ensureObjArray(g); + }); + + const catalogSolr = {}; + _.each(fieldConfig, (field, name) => { + let graphElement = _.filter(graph, (g) => { + return _.find(g['@type'], (gg) => gg === name) ? g : undefined; + }); + if (graphElement) { + _.each(graphElement, (ge) => { + if (Array.isArray(catalogSolr[name])) { + catalogSolr[name].push(catalog.getGraphElement(fieldConfig[name], graph, ge)); + } else { + catalogSolr[name] = [catalog.getGraphElement(fieldConfig[name], graph, ge)]; + } + }); + } + }); + + assert.strictEqual(catalogSolr.Dataset[0].record_type_s, 'Dataset', 'dataset not loaded'); + assert.strictEqual(catalogSolr.Person[0].record_type_s, 'Person', 'person 1 not loaded'); + assert.strictEqual(catalogSolr.Person[3].record_type_s, 'Person', 'person 1 not loaded'); + + }); + }); + + describe('farm to freeways graph - catalog solr', function () { + it('should load the graph into a catalog solr array', function () { + + const caPath = path.join(process.cwd() + '/test-data', 'FARMTOFREEWAYS_CATALOG.json'); + const ca = require(caPath); + + const fieldConfig = catalog.config; + + //Peter's idea is to convert everything into an array then it is safer to work to convert const graph = _.each(ca['@graph'], (g) => { return catalog.ensureObjArray(g); }); -- GitLab