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

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

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

Loading…
Cancel
Save