Skip to content

Commit e294db2

Browse files
committed
Initial test works
1 parent 6a9b6b1 commit e294db2

4 files changed

Lines changed: 23 additions & 10 deletions

File tree

chats/ldo/src/Chat.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SolidConnectedPlugin, SolidContainer, SolidContainerUri, SolidLeaf, Sol
33
import { ChatMessageShape, ChatShape } from "./.ldo/longChat.typings.js";
44
import { scheduleNewDayTrigger } from "./util/scheduleNewDayTrigger.js";
55
import { ChatMessageListShapeShapeType, ChatMessageShapeShapeType, ChatShapeShapeType } from "./.ldo/longChat.shapeTypes.js";
6-
import { getResource, throwIfErr } from "./util/resultHelpers.js";
6+
import { getResource, throwIfErr, throwIfErrOrAbsent } from "./util/resultHelpers.js";
77
import { v4 } from "uuid";
88
import { namedNode } from "@ldo/rdf-utils";
99
export class Chat {
@@ -126,7 +126,7 @@ export class Chat {
126126
container: SolidContainer
127127
): Promise<SolidLeaf | undefined> => {
128128
const indexResource = container.child("index.ttl");
129-
throwIfErr(await indexResource.readIfUnfetched());
129+
throwIfErrOrAbsent(await indexResource.readIfUnfetched());
130130
return indexResource;
131131
};
132132

@@ -135,7 +135,7 @@ export class Chat {
135135
levels: number
136136
): Promise<SolidLeaf | undefined> => {
137137
if (levels === 0) return getIndexIfExists(container);
138-
throwIfErr(await container.readIfUnfetched());
138+
throwIfErrOrAbsent(await container.readIfUnfetched());
139139
const mostRecent = getMostRecentContainer(container.children());
140140
if (!mostRecent) return undefined;
141141
return drillDownMostRecent(mostRecent, levels - 1);
@@ -145,10 +145,10 @@ export class Chat {
145145
const levelNames = ["Month", "Year", "Eternity"]; // Logical structure
146146
for (let depth = 0; depth < levelNames.length; depth++) {
147147
const parent = await container.getParentContainer() as SolidContainer;
148-
throwIfErr(await parent.readIfUnfetched());
148+
throwIfErrOrAbsent(await parent.readIfUnfetched());
149149
const previous = getPreviousContainer(parent.children(), container);
150150
if (previous) {
151-
throwIfErr(await previous.readIfUnfetched());
151+
throwIfErrOrAbsent(await previous.readIfUnfetched());
152152
return drillDownMostRecent(previous, depth); // Drill into [day, month, year]
153153
}
154154
container = parent;
@@ -236,10 +236,11 @@ export class Chat {
236236
* @returns
237237
*/
238238
public async getChatInfo(): Promise<ChatShape> {
239-
throwIfErr(await this.chatResource.readIfUnfetched());
239+
const result = throwIfErrOrAbsent(await this.chatResource.readIfUnfetched());
240+
console.log(result);
240241

241242
return this.dataset.usingType(ChatShapeShapeType)
242-
.fromSubject(this.chatResource.uri);
243+
.fromSubject(`${this.chatResource.uri}#this`);
243244
}
244245

245246
public async setChatInfo(chatInfo: Partial<ChatShape>): Promise<void> {
@@ -250,7 +251,7 @@ export class Chat {
250251
const cChatInfo = chatInfoTransaction
251252
.usingType(ChatShapeShapeType)
252253
.write(this.chatResource.uri)
253-
.fromSubject(this.chatResource.uri);
254+
.fromSubject(`${this.chatResource.uri}#this`);
254255
Object.assign(cChatInfo, chatInfo);
255256
throwIfErr(await chatInfoTransaction.commitToRemote());
256257
}

chats/ldo/src/util/resultHelpers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ export function throwIfErr<Results extends { isError: boolean }>(
77
return result as NonError<Results>;
88
}
99

10+
export function throwIfErrOrAbsent<
11+
Results extends { isError: boolean, type: string, resource: any }
12+
>(
13+
result: Results
14+
): NonError<Results> {
15+
const toReturn = throwIfErr(result);
16+
if (result.type === "absentReadSuccess") {
17+
throw new Error(`Resource ${result.resource.uri} is absent.`);
18+
}
19+
return toReturn;
20+
}
21+
1022
export function getResource<
1123
Results extends { isError: true } | { isError: false, resource: any }
1224
>(

chats/ldo/test/configs/components-config/unauthenticatedServer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
"overrideParameters": {
4747
"@type": "StaticFolderGenerator",
48-
"templateFolder": "./example/test-server/configs/template"
48+
"templateFolder": "./test/configs/template"
4949
}
5050
}
5151
]

chats/ldo/test/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe("integration", () => {
8080
it("Fetches chat information", async () => {
8181
const chatInfo = await sample1Chat.getChatInfo();
8282
expect(chatInfo["@id"]).toBe(SAMPLE_CHAT_1_INDEX_INFO["@id"]);
83-
expect(chatInfo.author).toBe(SAMPLE_CHAT_1_INDEX_INFO.author);
83+
expect(chatInfo.author).toEqual(SAMPLE_CHAT_1_INDEX_INFO.author);
8484
expect(chatInfo.created).toBe(SAMPLE_CHAT_1_INDEX_INFO.created);
8585
expect(chatInfo.title).toBe(SAMPLE_CHAT_1_INDEX_INFO.title);
8686
});

0 commit comments

Comments
 (0)