Fixed weird error when subscribing to notifications.

main
Jackson Morgan 8 months ago
parent 44575669e5
commit bb7a65b4a2
  1. 1
      packages/solid/.gitignore
  2. 7
      packages/solid/src/requester/requests/readResource.ts
  3. 3
      packages/solid/src/resource/Resource.ts
  4. 18
      packages/solid/test/Integration.test.ts
  5. 3
      packages/solid/test/solidServer.helper.ts

@ -0,0 +1 @@
data

@ -99,13 +99,9 @@ export async function readResource(
try { try {
const fetch = guaranteeFetch(options?.fetch); const fetch = guaranteeFetch(options?.fetch);
// Fetch options to determine the document type // Fetch options to determine the document type
console.log("Will make fetch");
console.log(uri);
const response = await fetch(uri, { const response = await fetch(uri, {
headers: { accept: "text/turtle, */*" }, headers: { accept: "text/turtle, */*" },
}); });
console.log("Lets just confirm its this fetch");
console.log(response);
if (response.status === 404) { if (response.status === 404) {
return { return {
isError: false, isError: false,
@ -132,9 +128,7 @@ export async function readResource(
if (contentType.startsWith("text/turtle")) { if (contentType.startsWith("text/turtle")) {
// Parse Turtle // Parse Turtle
console.log("Before text");
const rawTurtle = await response.text(); const rawTurtle = await response.text();
console.log("After Text");
if (options?.dataset) { if (options?.dataset) {
const result = await addRawTurtleToDataset( const result = await addRawTurtleToDataset(
rawTurtle, rawTurtle,
@ -172,7 +166,6 @@ export async function readResource(
}; };
} }
} catch (err) { } catch (err) {
console.log("We're in this error", err);
return UnexpectedResourceError.fromThrown(uri, err); return UnexpectedResourceError.fromThrown(uri, err);
} }
} }

@ -745,8 +745,7 @@ export abstract class Resource extends (EventEmitter as new () => TypedEmitter<{
protected async onNotification(message: NotificationMessage): Promise<void> { protected async onNotification(message: NotificationMessage): Promise<void> {
switch (message.type) { switch (message.type) {
case "Update": case "Update":
const readResult = await this.read(); await this.read();
console.log(readResult);
} }
} }

@ -43,6 +43,8 @@ import type { WacRule } from "../src/resource/wac/WacRule";
import type { GetStorageContainerFromWebIdSuccess } from "../src/requester/results/success/CheckRootContainerSuccess"; import type { GetStorageContainerFromWebIdSuccess } from "../src/requester/results/success/CheckRootContainerSuccess";
import { generateAuthFetch } from "./authFetch.helper"; import { generateAuthFetch } from "./authFetch.helper";
import { wait } from "./utils.helper"; import { wait } from "./utils.helper";
import fs from "fs/promises";
import path from "path";
const TEST_CONTAINER_SLUG = "test_ldo/"; const TEST_CONTAINER_SLUG = "test_ldo/";
const TEST_CONTAINER_URI = const TEST_CONTAINER_URI =
@ -173,21 +175,21 @@ describe("Integration", () => {
app.stop(); app.stop();
process.env.JEST_WORKER_ID = previousJestId; process.env.JEST_WORKER_ID = previousJestId;
process.env.NODE_ENV = previousNodeEnv; process.env.NODE_ENV = previousNodeEnv;
const testDataPath = path.join(__dirname, "../data");
await fs.rm(testDataPath, { recursive: true, force: true });
}); });
beforeEach(async () => { beforeEach(async () => {
fetchMock = jest.fn(authFetch); fetchMock = jest.fn(authFetch);
solidLdoDataset = createSolidLdoDataset({ fetch: fetchMock }); solidLdoDataset = createSolidLdoDataset({ fetch: fetchMock });
console.log(ROOT_CONTAINER, TEST_CONTAINER_SLUG);
// Create a new document called sample.ttl // Create a new document called sample.ttl
const result = await authFetch(ROOT_CONTAINER, { await authFetch(ROOT_CONTAINER, {
method: "POST", method: "POST",
headers: { headers: {
link: '<http://www.w3.org/ns/ldp#Container>; rel="type"', link: '<http://www.w3.org/ns/ldp#Container>; rel="type"',
slug: TEST_CONTAINER_SLUG, slug: TEST_CONTAINER_SLUG,
}, },
}); });
console.log("Create Result", result);
await authFetch(TEST_CONTAINER_ACL_URI, { await authFetch(TEST_CONTAINER_ACL_URI, {
method: "PUT", method: "PUT",
headers: { headers: {
@ -2021,7 +2023,6 @@ describe("Integration", () => {
*/ */
describe("Notification Subscriptions", () => { describe("Notification Subscriptions", () => {
it("Notification is propogated when a resource is updated", async () => { it("Notification is propogated when a resource is updated", async () => {
expect(true).toBe(true);
const spidermanNode = namedNode("http://example.org/#spiderman"); const spidermanNode = namedNode("http://example.org/#spiderman");
const foafNameNode = namedNode("http://xmlns.com/foaf/0.1/name"); const foafNameNode = namedNode("http://xmlns.com/foaf/0.1/name");
@ -2031,8 +2032,8 @@ describe("Integration", () => {
const spidermanCallback = jest.fn(); const spidermanCallback = jest.fn();
solidLdoDataset.addListener([spidermanNode, null, null, null], jest.fn()); solidLdoDataset.addListener([spidermanNode, null, null, null], jest.fn());
// const subscriptionResult = await resource.subscribeToNotifications(); const subscriptionResult = await resource.subscribeToNotifications();
// expect(subscriptionResult.type).toBe("subscribeToNotificationSuccess"); expect(subscriptionResult.type).toBe("subscribeToNotificationSuccess");
await authFetch(SAMPLE_DATA_URI, { await authFetch(SAMPLE_DATA_URI, {
method: "PATCH", method: "PATCH",
@ -2042,11 +2043,7 @@ describe("Integration", () => {
}, },
}); });
await wait(1000); await wait(1000);
process.env.AFTER = "TRUE";
await resource.read();
expect(spidermanCallback).toHaveBeenCalledTimes(1);
expect( expect(
solidLdoDataset.match( solidLdoDataset.match(
spidermanNode, spidermanNode,
@ -2054,6 +2051,7 @@ describe("Integration", () => {
literal("Peter Parker"), literal("Peter Parker"),
).size, ).size,
).toBe(1); ).toBe(1);
expect(spidermanCallback).toHaveBeenCalledTimes(1);
// // Notification is not propogated after unsubscribe // // Notification is not propogated after unsubscribe
// spidermanCallback.mockClear(); // spidermanCallback.mockClear();

@ -28,12 +28,13 @@ export async function createApp(): Promise<App> {
mainModulePath: resolveModulePath(""), mainModulePath: resolveModulePath(""),
typeChecking: false, typeChecking: false,
}, },
config: resolveModulePath("config/default.json"), config: resolveModulePath("config/file-root.json"),
variableBindings: {}, variableBindings: {},
shorthand: { shorthand: {
port: 3_001, port: 3_001,
loggingLevel: "off", loggingLevel: "off",
seedConfig: path.join(__dirname, "configs", "solid-css-seed.json"), seedConfig: path.join(__dirname, "configs", "solid-css-seed.json"),
rootFilePath: "./data",
}, },
}); });
} }

Loading…
Cancel
Save