Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
fix: test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ludwigschub committed Oct 3, 2023
1 parent f2267b8 commit 2cf9035
Show file tree
Hide file tree
Showing 10 changed files with 1,669 additions and 3,003 deletions.
3 changes: 0 additions & 3 deletions .example.env

This file was deleted.

7 changes: 0 additions & 7 deletions .vscode/settings.json

This file was deleted.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
"url": "https://github.com/ludwigschubi/shex-methods/issues"
},
"devDependencies": {
"@babel/preset-env": "7.16.4",
"@babel/preset-typescript": "7.16.0",
"@babel/helper-get-function-arity": "^7.16.7",
"@babel/preset-env": "^7.22.20",
"@babel/preset-typescript": "^7.23.0",
"@shexjs/neighborhood-api": "^1.0.0-alpha.25",
"@types/jest": "26.0.24",
"@types/n3": "^1.10.4",
Expand All @@ -58,12 +59,12 @@
"eslint-plugin-prettier": "3.4.1",
"gh-pages": "3.2.3",
"husky": "7.0.4",
"jest": "26.6.3",
"jest": "^29.7.0",
"lint-staged": "12.1.2",
"nodemon": "2.0.15",
"prettier": "2.5.1",
"rimraf": "3.0.2",
"shex-codegen": "^0.4.3",
"shex-codegen": "^0.4.9",
"solid-node-client": "2.1.0",
"ts-node": "10.4.0",
"typedoc": "0.22.10",
Expand Down
5 changes: 3 additions & 2 deletions shex-codegen.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# path to the folder or file with shape expressions
schema: "test/resources"
schema: 'test/resources'
generates:
# this will be the path of the generated file. It has to end with .ts
test/resources/shex.ts:
# the visitors to visit the schema with
- typescript
- typescript-methods
- typescript-methods
customMethodsImport: '../../src'
4 changes: 2 additions & 2 deletions src/handlers/create.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IndexedFormula, NamedNode, Statement, UpdateManager } from 'rdflib'
import { IndexedFormula, NamedNode, Statement } from 'rdflib'

import { QueryResult, Shape } from '../shape'
import {
ValidationResult,
getAllStatementsOfNode,
validateShex,
ValidationResult,
} from '../validate'

export interface CreateArgs<CreateShapeArgs> {
Expand Down
26 changes: 13 additions & 13 deletions test/handlers/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Literal } from 'rdflib';

import setupTests from '../setupTests';
import { Shape } from '../../lib';
import { Shape } from '../../src';
import { podUrl } from '../common';
import {
chatShex,
Expand Down Expand Up @@ -61,9 +61,9 @@ describe('.create()', () => {
expect(errors).toBeUndefined();
expect(data).toBeDefined();
expect(doc).toBe(testDoc);
expect(data.title).toBe('Test Chat');
expect(data.author).toBe(webId);
expect(data.type).toBe(ChatShapeType.LongChat);
expect(data?.title).toBe('Test Chat');
expect(data?.author).toBe(webId);
expect(data?.type).toBe(ChatShapeType.LongChat);
});

it('can create one shape in a new doc', async () => {
Expand All @@ -81,10 +81,10 @@ describe('.create()', () => {
expect(errors).toBeUndefined();
expect(data).toBeDefined();
expect(doc).toBe(newDoc);
expect(data.id).toBe(newChatIri);
expect(data.title).toBe('Test Chat');
expect(data.author).toBe(webId);
expect(data.type).toBe(ChatShapeType.LongChat);
expect(data?.id).toBe(newChatIri);
expect(data?.title).toBe('Test Chat');
expect(data?.author).toBe(webId);
expect(data?.type).toBe(ChatShapeType.LongChat);
});

it('can create one shape without type', async () => {
Expand All @@ -102,8 +102,8 @@ describe('.create()', () => {
expect(errors).toBeUndefined();
expect(data).toBeDefined();
expect(doc).toBe(testDoc);
expect(data.content).toBe('Test Message');
expect(data.maker).toBe(webId);
expect(data?.content).toBe('Test Message');
expect(data?.maker).toBe(webId);
});

it("throws error when data doesn't match cardinality", async () => {
Expand All @@ -121,7 +121,7 @@ describe('.create()', () => {
expect(doc).toBe(testDoc);
expect(data).toBeUndefined();
expect(errors).toBeDefined();
expect(errors.join('\n')).toContain('exceeds cardinality');
expect(errors?.join('\n')).toContain('exceeds cardinality');
});

it('throws error when shape with id already exists in doc', async () => {
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('.create()', () => {
data: {
id: secondChatIri,
type: ChatShapeType.LongChat,
title: 0,
title: 0 as unknown as string,
author: new URL(webId),
created: new Literal(new Date().toISOString()),
},
Expand All @@ -161,7 +161,7 @@ describe('.create()', () => {
expect(doc).toBe(testDoc);
expect(data).toBeUndefined();
expect(errors).toBeDefined();
expect(errors.join('\n')).toContain('Missing property');
expect(errors?.join('\n')).toContain('Missing property');
});

it("throws error when validating and context doesn't match", async () => {
Expand Down
16 changes: 10 additions & 6 deletions test/handlers/findOne.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,22 @@ describe('.findOne()', () => {
});
const { doc, data } = shape;
expect(doc).toBe(profileIri);
expect(data.name).toBe('Local Solid User');
expect(data['foaf:name']).toBe('Local Solid User');
expect(data.trustedApp['acl:origin']).toBe('http://example.org/');
expect(data).toBeDefined()
if (data && data.trustedApp) {
expect(data.name).toBe('Local Solid User');
expect(data['foaf:name']).toBe('Local Solid User');
expect(data.trustedApp['acl:origin']).toBe('http://example.org/');
}
});

it('can display document of one shape', async () => {
const shape = await solidProfile.findOne({
doc: profileIri,
where: { id: profileIri },
});
const { data } = shape;
expect(data.__doc).toBe(profileIri);
const { data, doc } = shape;
expect(data).toBeDefined()
expect(doc).toBe(profileIri);
});

it('should return an error for finding the wrong shape', async () => {
Expand Down
16 changes: 8 additions & 8 deletions test/handlers/update.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Literal } from 'rdflib';

import { Shape } from '../../lib';
import { Shape } from '../../src';
import { podUrl } from '../common';
import {
chatShex,
Expand Down Expand Up @@ -88,9 +88,9 @@ describe('.update()', () => {
expect(errors).toBeUndefined();
expect(data).toBeDefined();
expect(doc).toBe(testDoc);
expect(data.title).toBe(testString);
expect(data.author).toBe(profileIri);
expect(data.type).toBe(ChatShapeType.LongChat);
expect(data?.title).toBe(testString);
expect(data?.author).toBe(profileIri);
expect(data?.type).toBe(ChatShapeType.LongChat);
});

it('deletes values if they are empty', async () => {
Expand All @@ -105,7 +105,7 @@ describe('.update()', () => {
expect(errors).toBeUndefined();
expect(data).toBeDefined();
expect(doc).toBe(testDoc);
expect(data.sharedPreferences).toBeUndefined();
expect(data?.sharedPreferences).toBeUndefined();
});

it('can update a shape with a nested value', async () => {
Expand All @@ -131,7 +131,7 @@ describe('.update()', () => {
expect(errors).toBeUndefined();
expect(data).toBeDefined();
expect(doc).toBe(profileIri);
expect((data.trustedApp as TrustedAppShape)[0].origin).toBeDefined();
expect((data?.trustedApp as TrustedAppShape)[0].origin).toBeDefined();
});

it("throws error when data doesn't match cardinality", async () => {
Expand All @@ -146,7 +146,7 @@ describe('.update()', () => {
expect(doc).toBe(testDoc);
expect(data).toBeUndefined();
expect(errors).toBeDefined();
expect(errors.join('\n')).toContain('exceeds cardinality');
expect(errors?.join('\n')).toContain('exceeds cardinality');
});

it("throws error when data doesn't match shex", async () => {
Expand All @@ -161,7 +161,7 @@ describe('.update()', () => {
expect(doc).toBe(testDoc);
expect(data).toBeUndefined();
expect(errors).toBeDefined();
expect(errors.join('\n')).toContain('Missing property');
expect(errors?.join('\n')).toContain('Missing property');
});

it("throws error when transforming and context doesn't match", async () => {
Expand Down
6 changes: 4 additions & 2 deletions test/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { rmSync, existsSync } from 'fs';

import { SolidNodeClient } from 'solid-node-client';
import { SolidNodeClient } from 'solid-node-client/dist/esm';

export default (): SolidNodeClient => {
export const setup = (): SolidNodeClient => {
const client = new SolidNodeClient();
if (existsSync(`${process.cwd()}/testdata`)) {
rmSync(`${process.cwd()}/testdata`, { recursive: true });
}
return client;
};

export default setup
Loading

0 comments on commit 2cf9035

Please sign in to comment.