Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STUD-414] Make all tests work with Stardog 7+ #234

Merged
merged 10 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Universal Javascript fetch wrapper for communicating with the Stardog HTTP serve

[![npm](https://img.shields.io/npm/v/stardog.svg?style=flat-square)](https://www.npmjs.com/package/stardog)

<a href="http://stardog.com"><img src="http://stardog.com/img/stardog.png" style="margin: 0 auto; display: block; width: 250px"/></a>
<a href="http://stardog.com"><img src="https://d33wubrfki0l68.cloudfront.net/66e9dcff51317cfc11b9f3d4ce2917a11ba81681/543c1/img/stardog-logo-optimized.svg" style="margin: 0 auto; display: block; width: 250px"/></a>

## What is it?

Expand Down Expand Up @@ -63,15 +63,19 @@ If you have publishing rights, BE SURE TO RUN `npm version (major|minor|patch)`

After releasing, be sure to push to master, including the tags (so that the release is reflected on GitHub).

## Version details
## Version/Support Details

The current version of stardog.js has been tested against version 6.2.0 of Stardog. You are encouraged to use this library if you are using version 5 or greater of Stardog. However, there is very little code that is version specific in stardog.js. It is essentially just a convenience wrapper around `fetch`. It is very likely that many of the exposed methods will work on older versions of Stardog, but this has not been tested.
Each release of stardog.js is tested against the most recent version of Stardog available at the time of the release. The relationship between versions of stardog.js and versions of Stardog is detailed in the following table:

If you are using a really old version of Stardog (<= 3.0.0) you should stick with the legacy version of the library which is version 0.3.1.
| stardog.js Version | Supported Stardog Version(s) |
| ------------------ | ---------------------------- |
| 2.x.x | 7.x.x |
| 1.x.x | 5.x.x, 6.x.x |
| 0.x.x* | any version < 5 |

### Discontinued Versions
_* = No longer supported_

All versions of stardog.js prior to v1.0.0 have been discontinued and will not receive updates of any kind. If you are using a legacy version of stardog.js you can find the original documentation [here](http://stardog-union.github.io/stardog.js/docs/stardog.html). The most recent legacy version is 0.3.1.
We support and maintain a particular version of stardog.js only if the corresponding Stardog version(s) is (are) officially supported and maintained. For example, we no longer support v0.x.x of stardog.js, as the corresponding Stardog versions are no longer supported. (That said, later versions of stardog.js will often _mostly_ work with earlier Stardog versions. We just don't test this or make any guarantees to that effect.)

## Quick Example
```js
Expand Down
45 changes: 0 additions & 45 deletions test/copyDB.spec.js

This file was deleted.

3 changes: 2 additions & 1 deletion test/createDB.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('createDB()', () => {
return db.create(conn, database);
})
.then(res => {
expect(res.status).toBe(409);
// Database already exists
expect(res.headers.get('sd-error-code')).toBe('0D0DE2');
}));
});
17 changes: 13 additions & 4 deletions test/exportDB.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ describe('exportDB()', () => {
it('should return a response with content-disposition header and the attachment export file', () =>
db.exportData(conn, database).then(res => {
expect(res.status).toBe(200);
expect(res.body).toHaveLength(33);
expect(
res.headers.get('content-disposition').startsWith('attachment')
).toBe(true);
expect(res.body['@graph'].length).toBeGreaterThan(0);
}));

it('should return a response with content-disposition header and the attachment export file when using graph-uri param', () =>
Expand All @@ -33,7 +36,10 @@ describe('exportDB()', () => {
})
.then(res => {
expect(res.status).toBe(200);
expect(res.body).toHaveLength(33);
expect(
res.headers.get('content-disposition').startsWith('attachment')
).toBe(true);
expect(res.body['@graph'].length).toBeGreaterThan(0);
}));

describe('additionalHandlers', () => {
Expand Down Expand Up @@ -61,7 +67,10 @@ describe('exportDB()', () => {
})
.then(res => {
expect(res.status).toBe(200);
expect(res.body).toHaveLength(33);
expect(
res.headers.get('content-disposition').startsWith('attachment')
).toBe(true);
expect(res.body['@graph'].length).toBeGreaterThan(0);
});
});

Expand All @@ -74,7 +83,7 @@ describe('exportDB()', () => {
})
.then(res => {
expect(res.status).toBe(200);
expect(res.body.length).toBeUndefined();
expect(res.body['@graph']).toBeUndefined();
});
});
});
Expand Down
11 changes: 4 additions & 7 deletions test/graphStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@ describe('graph store protocol', () => {
graph
.doGet(conn, database)
.then(res => {
expect(res.body).toContain(
'http://purl.org/dc/elements/1.1/publisher'
);
expect(res.body).toContain('http://purl.org/dc/elements/1.1/');
return graph.doGet(conn, database, null);
})
.then(res => {
expect(res.body).toContain(
'http://purl.org/dc/elements/1.1/publisher'
);
expect(res.body).toContain('http://purl.org/dc/elements/1.1/');
}));

it('should retrieve other RDF serializations when specified', () =>
Expand Down Expand Up @@ -120,7 +116,8 @@ describe('graph store protocol', () => {
return graph.doGet(conn, database, makeGraph('alice'));
})
.then(res => {
expect(res.body).toBe('[ ]');
const jsonBody = JSON.parse(res.body);
expect(jsonBody['@graph']).toHaveLength(0);
}));
});
});
18 changes: 13 additions & 5 deletions test/graphql.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
} = require('./setup-database');

const textPlan =
'prefix : <http://api.stardog.com/>\n\nFrom all\nProjection(?0, ?1) [#1]\n`─ MergeJoin(?0) [#1]\n +─ Scan[POSC](?0, <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, :Character) [#1]\n `─ Scan[PSOC](?0, :name, ?1) [#1]\n';
'prefix : <http://api.stardog.com/>\n\nFrom named\nFrom default\nProjection(?0, ?1) [#1]\n`─ MergeJoin(?0) [#1]\n +─ Scan[POSC](?0, <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, :Character) [#1]\n `─ Scan[PSOC](?0, :name, ?1) [#1]\n';

const jsonPlan = {
cardinality: 1,
Expand Down Expand Up @@ -126,7 +126,15 @@ type Episode {
}));

it('updateSchema', () => {
const simplerSchema = `type Episode {
const simplerSchema = `schema {
query: QueryType
}

type QueryType {
Episode: Episode
}

type Episode {
index: Int!
name: String!
}`;
Expand Down Expand Up @@ -160,7 +168,7 @@ type Episode {
fields: { '0': { '1': 'name' } },
plan: textPlan,
sparql:
'SELECT *\nFROM <tag:stardog:api:context:all>\n{\n?0 rdf:type :Character .\n?0 :name ?1 .\n}\n',
'SELECT *\nFROM <tag:stardog:api:context:local>\n{\n?0 rdf:type :Character .\n?0 :name ?1 .\n}\n',
});
} else {
// Argument is not supported before 6.1.4
Expand All @@ -181,12 +189,12 @@ type Episode {
expect(res.body).toHaveProperty('data');
expect(res.body.data).toEqual({
sparql:
'SELECT *\nFROM <tag:stardog:api:context:all>\n{\n?0 rdf:type :Character .\n?0 :name ?1 .\n}\n',
'SELECT *\nFROM <tag:stardog:api:context:local>\n{\n?0 rdf:type :Character .\n?0 :name ?1 .\n}\n',
fields: { '0': { '1': 'name' } },
// > 6.1.3 captures snapshot versions of 6.1.4
plan: semver.gt(semver.coerce(stardogVersion), semver.coerce('6.1.3'))
? {
dataset: { from: 'all' },
dataset: { from: ['named', 'default'] },
plan: jsonPlan,
prefixes: { '': 'http://api.stardog.com/' },
}
Expand Down
94 changes: 50 additions & 44 deletions test/icv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ describe('icv', () => {
const conn = ConnectionFactory();

const beginTx = transaction.begin.bind(null, conn, database);
const rollbackTx = txId => transaction.rollback(conn, database, txId);

beforeAll(seedDatabase(database, { icv: { enabled: true } }));
beforeAll(
seedDatabase(database, {
icv: { enabled: true },
transaction: { isolation: 'SERIALIZABLE' }, // needed for ICV in Stardog 7+
})
);
afterAll(dropDatabase(database));

it('should add integrity constraint axioms', () =>
Expand All @@ -33,11 +39,10 @@ describe('icv', () => {
})
.then(res => {
expect(res.status).toBe(200);
expect(res.body.length).toBeGreaterThan(0);
return icv.clear(conn, database);
}));

// Skipping for now, as the server isn't returning the correct results
it.skip('should remove integrity constraint axioms', () =>
it('should remove integrity constraint axioms', () =>
icv
.add(conn, database, icvAxioms, { contentType: 'text/turtle' })
.then(() =>
Expand All @@ -49,7 +54,6 @@ describe('icv', () => {
})
.then(res => {
expect(res.status).toBe(200);
expect(res.body.length).toBe(0);
}));

it('should clear integrity constraint axioms', () =>
Expand All @@ -62,7 +66,6 @@ describe('icv', () => {
})
.then(res => {
expect(res.status).toBe(200);
expect(res.body.length).toBe(0);
}));

it('should convert constraint axioms to a SPARQL query', () =>
Expand All @@ -81,17 +84,18 @@ describe('icv', () => {
}));

it('should validate constraints in a transaction', () =>
beginTx()
.then(res => {
expect(res.status).toBe(200);
return icv.validateInTx(conn, database, res.transactionId, icvAxioms, {
beginTx().then(res => {
expect(res.status).toBe(200);
return icv
.validateInTx(conn, database, res.transactionId, icvAxioms, {
contentType: 'text/turtle',
});
})
.then(res => {
expect(res.status).toBe(200);
expect(res.body).toBe(false);
}));
})
.then(validateRes => {
expect(validateRes.status).toBe(200);
expect(validateRes.body).toBe(false);
})
.then(() => rollbackTx(res.transactionId));
}));

it('should report violations', () =>
icv.violations(conn, database, '').then(res => {
Expand All @@ -100,40 +104,42 @@ describe('icv', () => {
}));

it('should report violations in a transaction', () =>
beginTx()
.then(res => {
expect(res.status).toBe(200);
return icv.violationsInTx(conn, database, res.transactionId, '');
})
.then(res => {
expect(res.status).toBe(200);
expect(res.body).toBeNull();
}));
beginTx().then(res => {
expect(res.status).toBe(200);
return icv
.violationsInTx(conn, database, res.transactionId, '')
.then(violationsRes => {
expect(violationsRes.status).toBe(200);
expect(violationsRes.body).toBeNull();
})
.then(() => rollbackTx(res.transactionId));
}));

it('should produce violation reports', () =>
icv.report(conn, database, '').then(res => {
expect(res.status).toBe(200);
expect(res.body.length).not.toBe(0);
expect(res.body[0]).toHaveProperty('@id');
expect(res.body[0]).toHaveProperty('@type');
const reportData = res.body['@graph'];
expect(reportData.length).not.toBe(0);
expect(reportData[0]).toHaveProperty('@id');
expect(reportData[0]).toHaveProperty('@type');
// Can't use `toHaveProperty` below because jest thinks it's a path for nested properties
expect(res.body[0]['http://www.w3.org/ns/shacl#conforms']).toBeDefined();
expect(reportData[0]['sh:conforms']['@value']).toBe(true);
}));

it('should produce violation reports in a transaction', () =>
beginTx()
.then(res => {
expect(res.status).toBe(200);
return icv.reportInTx(conn, database, res.transactionId, '');
})
.then(res => {
expect(res.status).toBe(200);
expect(res.body.length).not.toBe(0);
expect(res.body[0]).toHaveProperty('@id');
expect(res.body[0]).toHaveProperty('@type');
// Can't use `toHaveProperty` below because jest thinks it's a path for nested properties
expect(
res.body[0]['http://www.w3.org/ns/shacl#conforms']
).toBeDefined();
}));
beginTx().then(res => {
expect(res.status).toBe(200);
return icv
.reportInTx(conn, database, res.transactionId, '')
.then(reportRes => {
expect(reportRes.status).toBe(200);
const reportData = reportRes.body['@graph'];
expect(reportData.length).not.toBe(0);
expect(reportData[0]).toHaveProperty('@id');
expect(reportData[0]).toHaveProperty('@type');
// Can't use `toHaveProperty` below because jest thinks it's a path for nested properties
expect(reportData[0]['sh:conforms']['@value']).toBe(true);
})
.then(() => rollbackTx(res.transactionId));
}));
});
5 changes: 4 additions & 1 deletion test/optimizeDB.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ describe('optimizeDB()', () => {
expect(res.status).toEqual(404);
}));

it('should optimize an online DB', () =>
// TODO: This case is currently skipped because there is no way in Stardog
// 7.3.x to ensure that the DB is ready for optimization (so, this often
// errors out). The erroring out should be fixed in Stardog 7.4.1.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has this been fixed in the 7.4.1 release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it! Updated the PR.

it.skip('should optimize an online DB', () =>
db.optimize(conn, database).then(res => {
expect(res.status).toEqual(200);
}));
Expand Down
Loading