Skip to content

Commit 5889ab1

Browse files
committed
chats: actually query the latest container
1 parent 685651c commit 5889ab1

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

chats/rdflib/src/module/queries/DateContainerQuery.spec.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DateContainerQuery } from "./DateContainerQuery";
2-
import { graph, sym } from "rdflib";
2+
import { graph, parse, sym } from "rdflib";
33

44
describe(DateContainerQuery.name, () => {
55
describe("query latest", () => {
@@ -68,5 +68,55 @@ describe(DateContainerQuery.name, () => {
6868
).queryLatest();
6969
expect(result).toEqual(null);
7070
});
71+
72+
it("returns the container name with the latest year number", () => {
73+
const store = graph();
74+
75+
parse(
76+
`
77+
@prefix ldp: <http://www.w3.org/ns/ldp#>.
78+
79+
<> ldp:contains <2022/>, <2024/>, <2023/>.
80+
81+
82+
<2022/> a ldp:Container .
83+
<2024/> a ldp:Container .
84+
<2023/> a ldp:Container .
85+
`,
86+
store,
87+
"https://pod.test/container/",
88+
);
89+
90+
const result = new DateContainerQuery(
91+
sym("https://pod.test/container/"),
92+
store,
93+
).queryLatest();
94+
expect(result).toEqual(sym("https://pod.test/container/2024/"));
95+
});
96+
97+
it("returns the container name with the month / day number", () => {
98+
const store = graph();
99+
100+
parse(
101+
`
102+
@prefix ldp: <http://www.w3.org/ns/ldp#>.
103+
104+
<> ldp:contains <05/>, <08/>, <06/>.
105+
106+
107+
<05/> a ldp:Container .
108+
<08/> a ldp:Container .
109+
<06/> a ldp:Container .
110+
`,
111+
store,
112+
"https://pod.test/container/2024/",
113+
);
114+
115+
const result = new DateContainerQuery(
116+
sym("https://pod.test/container/2024/"),
117+
store,
118+
).queryLatest();
119+
expect(result).toEqual(sym("https://pod.test/container/2024/08/"));
120+
});
71121
});
72122
});

chats/rdflib/src/module/queries/DateContainerQuery.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export class DateContainerQuery {
2020
this.container.doc(),
2121
);
2222
});
23-
return childContainers[0] ?? null; // TODO actually get latest
23+
24+
const years = childContainers.sort().reverse();
25+
26+
return years[0] ?? null;
2427
}
2528
}

0 commit comments

Comments
 (0)