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

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

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

@ -29,7 +29,7 @@ import type {
SolidContainerUri,
SolidLeafSlug,
} from "../types";
import type { AbsentReadSuccess, ReadSuccess } from "@ldo/connected";
import type { ReadSuccess } from "@ldo/connected";
import { AggregateSuccess, IgnoredInvalidUpdateSuccess } from "@ldo/connected";
import {
Unfetched,
@ -72,7 +72,7 @@ export class SolidContainer extends SolidResource {
/**
* 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

@ -50,7 +50,7 @@ export class SolidLeaf extends SolidResource {
/**
* 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

@ -78,7 +78,7 @@ export abstract class SolidResource
/**
* 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
@ -801,7 +801,7 @@ export abstract class SolidResource
const objectResource = this.context.dataset.getResource(message.object);
// Do Nothing if the resource is invalid.
if (objectResource.type === "InvalidIdentifierResouce") return;
if (objectResource.type === "leaf") {
if (objectResource.type === "SolidLeaf") {
switch (message.type) {
case "Update":
case "Add":

@ -37,8 +37,13 @@ import type {
UnexpectedResourceError,
UpdateDefaultGraphSuccess,
UpdateSuccess,
ConnectedLdoDataset,
} from "@ldo/connected";
import {
changeData,
commitData,
ConnectedLdoTransactionDataset,
} from "@ldo/connected";
import { changeData, commitData, ConnectedLdoDataset } from "@ldo/connected";
import { getStorageFromWebId } from "../src/getStorageFromWebId";
const TEST_CONTAINER_SLUG = "test_ldo/";
@ -131,7 +136,7 @@ async function testRequestLoads<ReturnVal>(
(async () => {
Object.entries(allLoadingValues).forEach(([key, value]) => {
if (
loadingResource.type === "container" &&
loadingResource.type === "SolidContainer" &&
(key === "isUploading" || key === "isUpdating")
) {
return;
@ -602,8 +607,8 @@ describe("Integration", () => {
it("Finds the root container", async () => {
const resource = solidLdoDataset.getResource(SAMPLE2_BINARY_URI);
const result = await resource.getRootContainer();
expect(result.type).toBe("container");
if (result.type !== "container") return;
expect(result.type).toBe("SolidContainer");
if (result.type !== "SolidContainer") return;
expect(result.uri).toBe(ROOT_CONTAINER);
expect(result.isRootContainer()).toBe(true);
});
@ -694,6 +699,7 @@ describe("Integration", () => {
SAMPLE_PROFILE_URI,
solidLdoDataset,
);
console.log(result);
expect(result.type).toBe("getStorageContainerFromWebIdSuccess");
const realResult = result as GetStorageContainerFromWebIdSuccess;
expect(realResult.storageContainers.length).toBe(2);
@ -1308,7 +1314,7 @@ describe("Integration", () => {
it("allows a transaction on a transaction", () => {
const transaction = solidLdoDataset.startTransaction();
const transaction2 = transaction.startTransaction();
expect(transaction2).toBeInstanceOf(ConnectedLdoDataset);
expect(transaction2).toBeInstanceOf(ConnectedLdoTransactionDataset);
});
/**
@ -1933,7 +1939,7 @@ describe("Integration", () => {
expect(
(wacResult as NoncompliantPodError<SolidLeaf | SolidContainer>).message,
).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