Skip to content

Commit

Permalink
Revert "[STUD-414] Make all tests work with Stardog 7+ (#234)"
Browse files Browse the repository at this point in the history
This reverts commit f4f77f1.
  • Loading branch information
Jason Rogers committed Oct 21, 2020
1 parent 27beed6 commit 9467507
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 111 deletions.
16 changes: 6 additions & 10 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="https://d33wubrfki0l68.cloudfront.net/66e9dcff51317cfc11b9f3d4ce2917a11ba81681/543c1/img/stardog-logo-optimized.svg" style="margin: 0 auto; display: block; width: 250px"/></a>
<a href="http://stardog.com"><img src="http://stardog.com/img/stardog.png" style="margin: 0 auto; display: block; width: 250px"/></a>

## What is it?

Expand Down Expand Up @@ -63,19 +63,15 @@ 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/Support Details
## Version details

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:
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.

| 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 |
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.

_* = No longer supported_
### Discontinued Versions

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.)
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.

## Quick Example
```js
Expand Down
45 changes: 45 additions & 0 deletions test/copyDB.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-env jest */

const { db } = require('../lib');
const {
seedDatabase,
dropDatabase,
generateDatabaseName,
ConnectionFactory,
} = require('./setup-database');

describe('db.copy()', () => {
const sourceDatabase = generateDatabaseName();
const destinationDatabase = generateDatabaseName();
let conn;

beforeAll(seedDatabase(sourceDatabase));
afterAll(dropDatabase(sourceDatabase));
afterAll(dropDatabase(destinationDatabase));

beforeEach(() => {
conn = ConnectionFactory();
});

it('should not copy an online DB', () =>
db
.copy(conn, sourceDatabase, destinationDatabase)
.then(() => db.list(conn))
.then(res => {
expect(res.status).toEqual(200);
// Destination shouldn't be listed because it's not online yet and therefor didn't get copied.
expect(res.body.databases).not.toContain(destinationDatabase);
expect(res.body.databases).toContain(sourceDatabase);
}));

it('should copy an offline DB', () =>
db
.offline(conn, sourceDatabase)
.then(() => db.copy(conn, sourceDatabase, destinationDatabase))
.then(() => db.list(conn))
.then(res => {
expect(res.status).toEqual(200);
expect(res.body.databases).toContain(destinationDatabase);
expect(res.body.databases).toContain(sourceDatabase);
}));
});
3 changes: 1 addition & 2 deletions test/createDB.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe('createDB()', () => {
return db.create(conn, database);
})
.then(res => {
// Database already exists
expect(res.headers.get('sd-error-code')).toBe('0D0DE2');
expect(res.status).toBe(409);
}));
});
17 changes: 4 additions & 13 deletions test/exportDB.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ 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.headers.get('content-disposition').startsWith('attachment')
).toBe(true);
expect(res.body['@graph'].length).toBeGreaterThan(0);
expect(res.body).toHaveLength(33);
}));

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

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

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

it('should retrieve other RDF serializations when specified', () =>
Expand Down Expand Up @@ -116,8 +120,7 @@ describe('graph store protocol', () => {
return graph.doGet(conn, database, makeGraph('alice'));
})
.then(res => {
const jsonBody = JSON.parse(res.body);
expect(jsonBody['@graph']).toHaveLength(0);
expect(res.body).toBe('[ ]');
}));
});
});
18 changes: 5 additions & 13 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 local 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';
'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';

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

it('updateSchema', () => {
const simplerSchema = `schema {
query: QueryType
}
type QueryType {
Episode: Episode
}
type Episode {
const simplerSchema = `type Episode {
index: Int!
name: String!
}`;
Expand Down Expand Up @@ -168,7 +160,7 @@ type Episode {
fields: { '0': { '1': 'name' } },
plan: textPlan,
sparql:
'SELECT *\nFROM <tag:stardog:api:context:local>\n{\n?0 rdf:type :Character .\n?0 :name ?1 .\n}\n',
'SELECT *\nFROM <tag:stardog:api:context:all>\n{\n?0 rdf:type :Character .\n?0 :name ?1 .\n}\n',
});
} else {
// Argument is not supported before 6.1.4
Expand Down Expand Up @@ -199,12 +191,12 @@ type Episode {
expect(res.body).toHaveProperty('data');
expect(res.body.data).toEqual({
sparql:
'SELECT *\nFROM <tag:stardog:api:context:local>\n{\n?0 rdf:type :Character .\n?0 :name ?1 .\n}\n',
'SELECT *\nFROM <tag:stardog:api:context:all>\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,
dataset: { from: 'all' },
plan: jsonPlan,
prefixes: { '': 'http://api.stardog.com/' },
}
Expand Down
94 changes: 44 additions & 50 deletions test/icv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@ 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 },
transaction: { isolation: 'SERIALIZABLE' }, // needed for ICV in Stardog 7+
})
);
beforeAll(seedDatabase(database, { icv: { enabled: true } }));
afterAll(dropDatabase(database));

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

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

it('should clear integrity constraint axioms', () =>
Expand All @@ -66,6 +62,7 @@ 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 @@ -84,18 +81,17 @@ 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(validateRes => {
expect(validateRes.status).toBe(200);
expect(validateRes.body).toBe(false);
})
.then(() => rollbackTx(res.transactionId));
}));
});
})
.then(res => {
expect(res.status).toBe(200);
expect(res.body).toBe(false);
}));

it('should report violations', () =>
icv.violations(conn, database, '').then(res => {
Expand All @@ -104,42 +100,40 @@ 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(violationsRes => {
expect(violationsRes.status).toBe(200);
expect(violationsRes.body).toBeNull();
})
.then(() => rollbackTx(res.transactionId));
}));
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();
}));

it('should produce violation reports', () =>
icv.report(conn, database, '').then(res => {
expect(res.status).toBe(200);
const reportData = res.body['@graph'];
expect(reportData.length).not.toBe(0);
expect(reportData[0]).toHaveProperty('@id');
expect(reportData[0]).toHaveProperty('@type');
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(reportData[0]['sh:conforms']['@value']).toBe(true);
expect(res.body[0]['http://www.w3.org/ns/shacl#conforms']).toBeDefined();
}));

it('should produce violation reports in a transaction', () =>
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));
}));
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();
}));
});
Loading

0 comments on commit 9467507

Please sign in to comment.