Skip to content

fix parseHydraDocumentation.test #34

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

Merged
merged 1 commit into from
Jun 15, 2018
Merged
Changes from all 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
86 changes: 58 additions & 28 deletions src/hydra/parseHydraDocumentation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ test("parse a Hydra documentation without authorization", () => {
});
});

test('Parse entrypoint without "@type" key', () => {
test('Parse entrypoint without "@type" key', async () => {
const entrypoint = `{
"@context": {
"@vocab": "http://localhost/docs.jsonld#",
Expand All @@ -1175,12 +1175,18 @@ test('Parse entrypoint without "@type" key', () => {

fetch.mockResponses([entrypoint, init], [docs, init]);

parseHydraDocumentation("http://localhost/").catch(data => {
expect(data.message).toBe('The API entrypoint has no "@type" key.');
});
const expectedError = { message: "" };

try {
await parseHydraDocumentation("http://localhost/");
} catch (error) {
expectedError.message = error.message;
}

expect(expectedError.message).toBe('The API entrypoint has no "@type" key.');
});

test('Parse entrypoint class without "supportedClass" key', () => {
test('Parse entrypoint class without "supportedClass" key', async () => {
const docs = `{
"@context": {
"@vocab": "http://localhost/docs.jsonld#",
Expand Down Expand Up @@ -1218,14 +1224,20 @@ test('Parse entrypoint class without "supportedClass" key', () => {

fetch.mockResponses([entrypoint, init], [docs, init]);

parseHydraDocumentation("http://localhost/").catch(data => {
expect(data.message).toBe(
'The API documentation has no "http://www.w3.org/ns/hydra/core#supportedClass" key or its value is not an array.'
);
});
const expectedError = { message: "" };

try {
await parseHydraDocumentation("http://localhost/");
} catch (error) {
expectedError.message = error.message;
}

expect(expectedError.message).toBe(
'The API documentation has no "http://www.w3.org/ns/hydra/core#supportedClass" key or its value is not an array.'
);
});

test('Parse entrypoint class without "supportedProperty" key', () => {
test('Parse entrypoint class without "supportedProperty" key', async () => {
const docs = `{
"@context": {
"@vocab": "http://localhost/docs.jsonld#",
Expand Down Expand Up @@ -1276,33 +1288,51 @@ test('Parse entrypoint class without "supportedProperty" key', () => {

fetch.mockResponses([entrypoint, init], [docs, init]);

parseHydraDocumentation("http://localhost/").catch(data => {
expect(data.message).toBe(
'The entrypoint definition has no "http://www.w3.org/ns/hydra/core#supportedProperty" key or it is not an array.'
);
});
const expectedError = { message: "" };

try {
await parseHydraDocumentation("http://localhost/");
} catch (error) {
expectedError.message = error.message;
}

expect(expectedError.message).toBe(
'The entrypoint definition has no "http://www.w3.org/ns/hydra/core#supportedProperty" key or it is not an array.'
);
});

test("Invalid docs JSON", () => {
test("Invalid docs JSON", async () => {
const docs = `{foo,}`;

fetch.mockResponses([entrypoint, init], [docs, init]);

parseHydraDocumentation("http://localhost/").catch(data => {
expect(data).toHaveProperty("api");
expect(data).toHaveProperty("response");
expect(data).toHaveProperty("status");
});
let expectedError = {};

try {
await parseHydraDocumentation("http://localhost/");
} catch (error) {
expectedError = error;
}

expect(expectedError).toHaveProperty("api");
expect(expectedError).toHaveProperty("response");
expect(expectedError).toHaveProperty("status");
});

test("Invalid entrypoint JSON", () => {
test("Invalid entrypoint JSON", async () => {
const entrypoint = `{foo,}`;

fetch.mockResponses([entrypoint, init], [docs, init]);

parseHydraDocumentation("http://localhost/").catch(data => {
expect(data).toHaveProperty("api");
expect(data).toHaveProperty("response");
expect(data).toHaveProperty("status");
});
let expectedError = {};

try {
await parseHydraDocumentation("http://localhost/");
} catch (error) {
expectedError = error;
}

expect(expectedError).toHaveProperty("api");
expect(expectedError).toHaveProperty("response");
expect(expectedError).toHaveProperty("status");
});