1.1.0 • Published 9 months ago

@entryscape/efix v1.1.0

Weekly downloads
-
License
-
Repository
bitbucket
Last release
9 months ago

Entry-Fixture - efix

This library is responsible for starting an EntryStore instance and loading it with contexts and entries based on a directory structure.

The fixture structure

To create a fixture simply create a folder structure that looks like:

fixtures
  - basic
    - 1.json
    - 2.json
  - repeatme_2
    - car_3.json

This structure will create three contexts in the EntryStore instance with contextIds basic, repeatme_1 and repeatme_2. The basic context will have exactly two entries with entryIds 1 and 2 while both the repeatme contexts will have three entries each with entryIds like car_1, car_2 and car_3.

To make sure each entry is created with metadata it should look like:

{
  "link": "http://example.com/ex1",
  "metadata": {
    "http://example.com/ex1": {
      "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": [
         { "value": "http://www.w3.org/ns/dcat#Dataset", "type": "uri" }
      ],
      "http://purl.org/dc/terms/title": [
         { "value": "example 1", "type": "literal" }
      ]
    }
  }
}

Where the link parameter indicates the resourceURI of a link entry. If no link is provided a local entry will be created where the resourceURI is minted. For instance if the contextId is basic and entryId is 1 the minted resourceURI will be http://127.0.0.1:8282/basic/resource/1.

The metadata structure follows the RDF/JSON format. If a local entry is to be created with this format the resourecURI should be given simply as '_newId', e.g.:

{
  "metadata": {
    "_newId": {
      "http://purl.org/dc/terms/title": [
        { "value": "example 1", "type": "literal" }
      ]
    }
  }
}

Another alternative is to use a simplified metadata format where the resourceURI is not needed, i.e.:

{
  "link": "http://example.com/ex2",
  "metadata_simple": {
    "rdf:type": "U:dcat:Dataset",
    "dcterms:title": "L:example 2"
  }
}

Using the efix-start and efix-stop commands in another project

Let us assume you have another project where you need to run some tests against an entrystore instance. To achieve this you need to first add this project as a dependency in package.json:

 dependencies: {
   "@entryscape/efix": "1.0.0"
   ...
 }

Second, you need to provide a fixture folder according to above. You can call the folder anything you want, if nothing is provided as parameter it is assumed to be called fixtures.

Third, you need to run the efix-start command before your test and efix-stop after your test. Typically this achieved as part of your test command:

"scripts": {
  "pretest": "efix-start",
  "test": "NODE_OPTIONS='--experimental-vm-modules' jest; JEST_EXIT=$?; npm run efix-stop; exit $TEST_EXIT"
}

Note that we cannot use a posttest script as that would not run if the tests fail. (The effect would be that the docker instance with the fixtures would not be stopped and the next time you run the tests it will not be a clean instance.)

If you choose another name for your fixture folder, just provide that as a parameter to the efix-start command. Furthermore, you may add a third parameter with milliseconds to increase the delay before your tests can start running to give the solr index a fair chance to complete the indexing process. Hence, the commend would then be:

"pretest": "efix-start myfixturefolder 5000"

Finally, you should probably add entrystore.log to your .gitignore file as this is an automatically created log file from entrystore.

Writing tests based on efix

To write tests you need to first provide the fixture folder. Second you need to connect to the right EntryStore instance and authenticate. The efix library provides the right config for you:

import { EntryStore } from "@entryscape/entrystore-js";
import { config } from '@entryscape/efix';

const es = new EntryStore(config.repository);
es.getAuth().login(config.user, config.password).then(() => {
    // authenticated, make requests against the fixtures.
});

Furthermore, it might also be useful to load the fixtures without adding them to a EntryStore instance. This can be done via the dryRun mode:

import { EntryStore } from "@entryscape/entrystore-js";
import { efix, silent } from '@entryscape/efix';

// load the fixtures in dry run with a silent logger.
efix('fixtures', true, silent).then(({fixtures}) => {
   // fixtures corresponds to the fixture folder in the following structure:
   // {
   //    "basic1": {
   //      "http://example.com/ex1": // entry or prototypeentry instance
   //    }
   // }
});
1.1.0

9 months ago

1.0.0

9 months ago