-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract more helper methods and allow to configure rdflib store, fetc…
…her and updater from outside the module
- Loading branch information
Showing
8 changed files
with
129 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import {ContactsModule} from '../dist/rdflib/index.js'; | ||
import {Fetcher, graph, UpdateManager} from "rdflib"; | ||
|
||
const contacts = new ContactsModule({}) | ||
const store = graph() | ||
const fetcher = new Fetcher(store) | ||
const updater = new UpdateManager(store) | ||
const contacts = new ContactsModule({store, fetcher, updater}) | ||
|
||
const result = await contacts.readAddressBook("http://localhost:3000/alice/public-contacts/index.ttl#this") | ||
console.log(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { when } from "jest-when"; | ||
import { createAddressBook } from "./createAddressBook"; | ||
import { ContactsModuleRdfLib } from "./ContactsModuleRdfLib"; | ||
import { executeUpdate } from "./executeUpdate"; | ||
import { Fetcher, graph, UpdateManager } from "rdflib"; | ||
|
||
jest.mock("./createAddressBook"); | ||
jest.mock("./executeUpdate"); | ||
|
||
describe("ContactsModuleRdfLib", () => { | ||
describe("createAddressBook", () => { | ||
const fakeOperation = { | ||
uri: "https://pod.test/alice/118b9dc2-dacb-42e4-9d8c-6078aa832f51/index.ttl#this", | ||
insertions: [], | ||
deletions: [], | ||
filesToCreate: [], | ||
}; | ||
|
||
let result: string; | ||
let fetcher: Fetcher; | ||
let updater: UpdateManager; | ||
beforeEach(async () => { | ||
jest.clearAllMocks(); | ||
// given | ||
when(createAddressBook) | ||
.calledWith("https://pod.test/alice/", "My Contacts") | ||
.mockReturnValue(fakeOperation); | ||
|
||
const store = graph(); | ||
fetcher = new Fetcher(store); | ||
updater = new UpdateManager(store); | ||
const module = new ContactsModuleRdfLib({ store, fetcher, updater }); | ||
|
||
// when | ||
result = await module.createAddressBook({ | ||
container: "https://pod.test/alice/", | ||
name: "My Contacts", | ||
}); | ||
}); | ||
|
||
it("returns the created URI", () => { | ||
// then | ||
expect(result).toEqual( | ||
"https://pod.test/alice/118b9dc2-dacb-42e4-9d8c-6078aa832f51/index.ttl#this", | ||
); | ||
}); | ||
|
||
it("executes the update operation", () => { | ||
// then | ||
expect(executeUpdate).toHaveBeenCalledWith( | ||
fetcher, | ||
updater, | ||
fakeOperation, | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Fetcher, UpdateManager } from "rdflib"; | ||
import { UpdateOperation } from "./createAddressBook"; | ||
|
||
export async function executeUpdate( | ||
fetcher: Fetcher, | ||
updater: UpdateManager, | ||
operation: UpdateOperation, | ||
) { | ||
await updater.update(operation.deletions, operation.insertions); | ||
operation.filesToCreate.map((file) => { | ||
createEmptyTurtleFile(fetcher, file.uri); | ||
}); | ||
} | ||
|
||
function createEmptyTurtleFile(fetcher: Fetcher, uri: string) { | ||
return fetcher.webOperation("PUT", uri, { | ||
contentType: "text/turtle", | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters