solid-connected tests work

main
Jackson Morgan 6 months ago
parent 2c591a2757
commit 4e6e0355b7
  1. 26
      packages/connected-solid/src/getStorageFromWebId.ts
  2. 2
      packages/connected-solid/src/requester/requests/createDataResource.ts
  3. 2
      packages/connected-solid/src/requester/requests/readResource.ts
  4. 4
      packages/connected-solid/src/resources/SolidContainer.ts
  5. 2
      packages/connected-solid/src/resources/SolidLeaf.ts
  6. 4
      packages/connected-solid/src/resources/SolidResource.ts
  7. 18
      packages/connected-solid/test/Integration.test.ts

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected"; import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected";
import type { SolidContainerUri, SolidLeafUri } from "./types"; import type { SolidContainerUri, SolidLeafUri } from "./types";
import type { GetStorageContainerFromWebIdSuccess } from "./requester/results/success/CheckRootContainerSuccess"; import { GetStorageContainerFromWebIdSuccess } from "./requester/results/success/CheckRootContainerSuccess";
import type { CheckRootResultError } from "./requester/requests/checkRootContainer"; import type { CheckRootResultError } from "./requester/requests/checkRootContainer";
import type { ReadResultError } from "./requester/requests/readResource"; import type { ReadResultError } from "./requester/requests/readResource";
import type { NoRootContainerError } from "./requester/results/error/NoRootContainerError"; import type { NoRootContainerError } from "./requester/results/error/NoRootContainerError";
@ -42,26 +42,20 @@ export async function getStorageFromWebId(
.usingType(ProfileWithStorageShapeType) .usingType(ProfileWithStorageShapeType)
.fromSubject(webId); .fromSubject(webId);
if (profile.storage && profile.storage.size > 0) { if (profile.storage && profile.storage.size > 0) {
profile.storage.forEach((item) => console.log(item["@id"]));
const containers = profile.storage const containers = profile.storage
.map((storageNode) => .map((storageNode) =>
dataset.getResource(storageNode["@id"] as SolidContainerUri), dataset.getResource(storageNode["@id"] as SolidContainerUri),
) )
.filter( .filter((container): container is SolidContainer => {
(container): container is SolidContainer => return container.type === "SolidContainer";
container.type === "SolidContainer", });
); console.log(containers);
return {
type: "getStorageContainerFromWebIdSuccess", return new GetStorageContainerFromWebIdSuccess(containers);
isError: false,
storageContainers: containers,
};
} }
const getContainerResult = await webIdResource.getRootContainer(); const getContainerResult = await webIdResource.getRootContainer();
if (getContainerResult.type === "container") if (getContainerResult.type === "SolidContainer")
return { return new GetStorageContainerFromWebIdSuccess([getContainerResult]);
type: "getStorageContainerFromWebIdSuccess",
isError: false,
storageContainers: [getContainerResult],
};
return getContainerResult; return getContainerResult;
} }

@ -225,7 +225,7 @@ export async function createDataResource(
"content-type": "text/turtle", "content-type": "text/turtle",
slug: getSlug(resource.uri), slug: getSlug(resource.uri),
}; };
if (resource.type === "container") { if (resource.type === "SolidContainer") {
headers.link = '<http://www.w3.org/ns/ldp#Container>; rel="type"'; headers.link = '<http://www.w3.org/ns/ldp#Container>; rel="type"';
} }
const response = await fetch(parentUri, { const response = await fetch(parentUri, {

@ -153,7 +153,7 @@ export async function readResource(
| NoncompliantPodError<SolidLeaf> | NoncompliantPodError<SolidLeaf>
| NoncompliantPodError<SolidContainer>; | NoncompliantPodError<SolidContainer>;
} }
if (resource.type === "container") { if (resource.type === "SolidContainer") {
const result = checkHeadersForRootContainer(resource, response.headers); const result = checkHeadersForRootContainer(resource, response.headers);
return new ContainerReadSuccess( return new ContainerReadSuccess(
resource, resource,

@ -29,7 +29,7 @@ import type {
SolidContainerUri, SolidContainerUri,
SolidLeafSlug, SolidLeafSlug,
} from "../types"; } from "../types";
import type { AbsentReadSuccess, ReadSuccess } from "@ldo/connected"; import type { ReadSuccess } from "@ldo/connected";
import { AggregateSuccess, IgnoredInvalidUpdateSuccess } from "@ldo/connected"; import { AggregateSuccess, IgnoredInvalidUpdateSuccess } from "@ldo/connected";
import { import {
Unfetched, Unfetched,
@ -72,7 +72,7 @@ export class SolidContainer extends SolidResource {
/** /**
* Indicates that this resource is a container resource * Indicates that this resource is a container resource
*/ */
readonly type = "container" as const; readonly type = "SolidContainer" as const;
/** /**
* Indicates that this resource is not an error * Indicates that this resource is not an error

@ -50,7 +50,7 @@ export class SolidLeaf extends SolidResource {
/** /**
* Indicates that this resource is a leaf resource * Indicates that this resource is a leaf resource
*/ */
readonly type = "leaf" as const; readonly type = "SolidLeaf" as const;
/** /**
* Indicates that this resource is not an error * Indicates that this resource is not an error

@ -78,7 +78,7 @@ export abstract class SolidResource
/** /**
* The type of resource (leaf or container) * The type of resource (leaf or container)
*/ */
abstract readonly type: "leaf" | "container"; abstract readonly type: "SolidLeaf" | "SolidContainer";
/** /**
* The status of the last request made for this resource * The status of the last request made for this resource
@ -801,7 +801,7 @@ export abstract class SolidResource
const objectResource = this.context.dataset.getResource(message.object); const objectResource = this.context.dataset.getResource(message.object);
// Do Nothing if the resource is invalid. // Do Nothing if the resource is invalid.
if (objectResource.type === "InvalidIdentifierResouce") return; if (objectResource.type === "InvalidIdentifierResouce") return;
if (objectResource.type === "leaf") { if (objectResource.type === "SolidLeaf") {
switch (message.type) { switch (message.type) {
case "Update": case "Update":
case "Add": case "Add":

@ -37,8 +37,13 @@ import type {
UnexpectedResourceError, UnexpectedResourceError,
UpdateDefaultGraphSuccess, UpdateDefaultGraphSuccess,
UpdateSuccess, UpdateSuccess,
ConnectedLdoDataset,
} from "@ldo/connected";
import {
changeData,
commitData,
ConnectedLdoTransactionDataset,
} from "@ldo/connected"; } from "@ldo/connected";
import { changeData, commitData, ConnectedLdoDataset } from "@ldo/connected";
import { getStorageFromWebId } from "../src/getStorageFromWebId"; import { getStorageFromWebId } from "../src/getStorageFromWebId";
const TEST_CONTAINER_SLUG = "test_ldo/"; const TEST_CONTAINER_SLUG = "test_ldo/";
@ -131,7 +136,7 @@ async function testRequestLoads<ReturnVal>(
(async () => { (async () => {
Object.entries(allLoadingValues).forEach(([key, value]) => { Object.entries(allLoadingValues).forEach(([key, value]) => {
if ( if (
loadingResource.type === "container" && loadingResource.type === "SolidContainer" &&
(key === "isUploading" || key === "isUpdating") (key === "isUploading" || key === "isUpdating")
) { ) {
return; return;
@ -602,8 +607,8 @@ describe("Integration", () => {
it("Finds the root container", async () => { it("Finds the root container", async () => {
const resource = solidLdoDataset.getResource(SAMPLE2_BINARY_URI); const resource = solidLdoDataset.getResource(SAMPLE2_BINARY_URI);
const result = await resource.getRootContainer(); const result = await resource.getRootContainer();
expect(result.type).toBe("container"); expect(result.type).toBe("SolidContainer");
if (result.type !== "container") return; if (result.type !== "SolidContainer") return;
expect(result.uri).toBe(ROOT_CONTAINER); expect(result.uri).toBe(ROOT_CONTAINER);
expect(result.isRootContainer()).toBe(true); expect(result.isRootContainer()).toBe(true);
}); });
@ -694,6 +699,7 @@ describe("Integration", () => {
SAMPLE_PROFILE_URI, SAMPLE_PROFILE_URI,
solidLdoDataset, solidLdoDataset,
); );
console.log(result);
expect(result.type).toBe("getStorageContainerFromWebIdSuccess"); expect(result.type).toBe("getStorageContainerFromWebIdSuccess");
const realResult = result as GetStorageContainerFromWebIdSuccess; const realResult = result as GetStorageContainerFromWebIdSuccess;
expect(realResult.storageContainers.length).toBe(2); expect(realResult.storageContainers.length).toBe(2);
@ -1308,7 +1314,7 @@ describe("Integration", () => {
it("allows a transaction on a transaction", () => { it("allows a transaction on a transaction", () => {
const transaction = solidLdoDataset.startTransaction(); const transaction = solidLdoDataset.startTransaction();
const transaction2 = transaction.startTransaction(); const transaction2 = transaction.startTransaction();
expect(transaction2).toBeInstanceOf(ConnectedLdoDataset); expect(transaction2).toBeInstanceOf(ConnectedLdoTransactionDataset);
}); });
/** /**
@ -1933,7 +1939,7 @@ describe("Integration", () => {
expect( expect(
(wacResult as NoncompliantPodError<SolidLeaf | SolidContainer>).message, (wacResult as NoncompliantPodError<SolidLeaf | SolidContainer>).message,
).toBe( ).toBe(
`Response from card.acl is not compliant with the Solid Specification: Request returned noncompliant turtle: Unexpected "BAD" on line 1.\nBAD TURTLE`, `Response from http://localhost:3001/test_ldo/sample.ttl is not compliant with the Solid Specification: Request returned noncompliant turtle: Unexpected "BAD" on line 1.\nBAD TURTLE`,
); );
}); });

Loading…
Cancel
Save