Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalef committed Oct 30, 2023
1 parent 3aca7fe commit 23bb18f
Show file tree
Hide file tree
Showing 8 changed files with 662 additions and 311 deletions.
870 changes: 610 additions & 260 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions src/tests/collection_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("DocumentCollection", () => {

it("sends correct data structure to server", async () => {
fetchMock.mockResponseOnce(
JSON.stringify([{ uuid: "1234", ...mockDocuments[0] }])
JSON.stringify([{ uuid: "1234", ...mockDocuments[0] }]),
);

const collection = new DocumentCollection(mockClient, mockCollection);
Expand All @@ -100,7 +100,7 @@ describe("DocumentCollection", () => {
is_auto_embedded: false,
});
const result = await collection.addDocuments(
mockDocumentsWithEmbeddings
mockDocumentsWithEmbeddings,
);

expect(result).toEqual(mockResponse);
Expand Down Expand Up @@ -179,7 +179,7 @@ describe("DocumentCollection", () => {
uuid: "1234",
documentId: "doc1",
metadata: { author: "John" },
})
}),
).rejects.toThrow("Collection name must be provided");
});

Expand All @@ -190,7 +190,7 @@ describe("DocumentCollection", () => {
uuid: "",
documentId: "doc1",
metadata: { author: "John" },
})
}),
).rejects.toThrow("Document must have a uuid");
});
});
Expand Down Expand Up @@ -225,14 +225,14 @@ describe("DocumentCollection", () => {
name: "",
});
await expect(collection.deleteDocument("1234")).rejects.toThrow(
"Collection name must be provided"
"Collection name must be provided",
);
});

it("throws error when document uuid is not provided", async () => {
const collection = new DocumentCollection(mockClient, mockCollection);
await expect(collection.deleteDocument("")).rejects.toThrow(
"Document must have a uuid"
"Document must have a uuid",
);
});
});
Expand Down Expand Up @@ -267,14 +267,14 @@ describe("DocumentCollection", () => {
name: "",
});
await expect(collection.getDocument("1234")).rejects.toThrow(
"Collection name must be provided"
"Collection name must be provided",
);
});

it("throws error when document uuid is not provided", async () => {
const collection = new DocumentCollection(mockClient, mockCollection);
await expect(collection.getDocument("")).rejects.toThrow(
"Document must have a uuid"
"Document must have a uuid",
);
});
});
Expand Down Expand Up @@ -329,7 +329,7 @@ describe("DocumentCollection", () => {
name: "",
});
await expect(
collection.getDocuments(["doc1", "doc2"])
collection.getDocuments(["doc1", "doc2"]),
).rejects.toThrow("Collection name must be provided");
});
});
Expand Down Expand Up @@ -357,7 +357,7 @@ describe("DocumentCollection", () => {
JSON.stringify({
results: expectedDocuments,
query_vector: [0.5, 0.5],
})
}),
);

const collection = new DocumentCollection(mockClient, mockCollection);
Expand All @@ -372,7 +372,7 @@ describe("DocumentCollection", () => {
JSON.stringify({
results: expectedDocuments,
query_vector: [0.5, 0.5],
})
}),
);

const collection = new DocumentCollection(mockClient, mockCollection);
Expand All @@ -387,7 +387,7 @@ describe("DocumentCollection", () => {
name: "",
});
await expect(
collection.search({ text: "Test document" })
collection.search({ text: "Test document" }),
).rejects.toThrow("Collection name must be provided");
});
});
Expand Down
20 changes: 10 additions & 10 deletions src/tests/document_manager_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("CollectionManager", () => {
describe("addCollection", () => {
it("throws error when embeddingDimensions is not a positive integer", async () => {
await expect(
manager.addCollection({ name: "test", embeddingDimensions: -1 })
manager.addCollection({ name: "test", embeddingDimensions: -1 }),
).rejects.toThrow("embeddingDimensions must be a positive integer");
});

Expand All @@ -36,21 +36,21 @@ describe("CollectionManager", () => {
fetchMock.mockResponseOnce(JSON.stringify(mockCollection));
await manager.addCollection({ name: "test", embeddingDimensions: 2 });
expect(fetchMock.mock.calls[1][0]).toEqual(
`${BASE_URL}/collection/test`
`${BASE_URL}/collection/test`,
);
expect(fetchMock.mock.calls[1][1]?.method).toEqual("POST");
expect(
(fetchMock.mock.calls[1][1]?.headers as Record<string, string>)?.[
"Content-Type"
]
],
).toEqual("application/json");
});
});

describe("getCollection", () => {
it("throws error when name is not provided", async () => {
await expect(manager.getCollection("")).rejects.toThrow(
"Collection name must be provided"
"Collection name must be provided",
);
});

Expand All @@ -59,7 +59,7 @@ describe("CollectionManager", () => {
await manager.getCollection("test");
// needs to be the second call because the first call is to healthz
expect(fetchMock.mock.calls[1][0]).toEqual(
`${BASE_URL}/collection/test`
`${BASE_URL}/collection/test`,
);
});
});
Expand All @@ -75,13 +75,13 @@ describe("CollectionManager", () => {
fetchMock.mockResponseOnce(JSON.stringify(testData));
await manager.updateCollection(testData);
expect(fetchMock.mock.calls[1][0]).toEqual(
`${BASE_URL}/collection/test`
`${BASE_URL}/collection/test`,
);
expect(fetchMock.mock.calls[1][1]?.method).toEqual("PATCH");
expect(
(fetchMock.mock.calls[1][1]?.headers as Record<string, string>)?.[
"Content-Type"
]
],
).toEqual("application/json");
});
});
Expand Down Expand Up @@ -112,7 +112,7 @@ describe("CollectionManager", () => {
expect(collection).toBeInstanceOf(DocumentCollectionModel);
expect(collection.name).toEqual(collectionsData[i].name);
expect(collection.description).toEqual(
collectionsData[i].description
collectionsData[i].description,
);
expect(collection.metadata).toEqual(collectionsData[i].metadata);
});
Expand All @@ -122,15 +122,15 @@ describe("CollectionManager", () => {
describe("deleteCollection", () => {
it("throws error when collectionName is not provided", async () => {
await expect(manager.deleteCollection("")).rejects.toThrow(
"Collection name must be provided"
"Collection name must be provided",
);
});

it("calls the correct endpoint with the correct method and headers", async () => {
fetchMock.mockResponseOnce(JSON.stringify({}));
await manager.deleteCollection("test");
expect(fetchMock.mock.calls[1][0]).toEqual(
`${BASE_URL}/collection/test`
`${BASE_URL}/collection/test`,
);
expect(fetchMock.mock.calls[1][1]?.method).toEqual("DELETE");
});
Expand Down
41 changes: 21 additions & 20 deletions src/tests/memory_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ describe("ZepClient", () => {

const sessions = await client.memory.listSessions();

expect(sessions).toEqual(responseData.map((session) => new Session(session)));
expect(sessions).toEqual(
responseData.map((session) => new Session(session)),
);
});

// Test for retrieving sessions with limit
Expand All @@ -135,7 +137,9 @@ describe("ZepClient", () => {

const sessions = await client.memory.listSessions(1);

expect(sessions).toEqual(responseData.map((session) => new Session(session)));
expect(sessions).toEqual(
responseData.map((session) => new Session(session)),
);
});
});

Expand Down Expand Up @@ -181,7 +185,7 @@ describe("ZepClient", () => {
fetchMock.mockResponses(
JSON.stringify(expectedSessionsData[0]),
JSON.stringify(expectedSessionsData[1]),
JSON.stringify([]) // empty response to indicate end of list
JSON.stringify([]), // empty response to indicate end of list
);

const sessionsChunked = [];
Expand All @@ -193,9 +197,6 @@ describe("ZepClient", () => {
});
});




// Test Suite for getMemory()
describe("getMemory", () => {
// Test for retrieving memory for a session
Expand Down Expand Up @@ -226,7 +227,7 @@ describe("ZepClient", () => {
uuid: "",
}),
metadata: {},
})
}),
);
});
});
Expand All @@ -236,7 +237,7 @@ describe("ZepClient", () => {
fetchMock.mockResponseOnce(JSON.stringify({}), { status: 404 });

await expect(client.memory.getMemory("test-session")).rejects.toThrow(
NotFoundError
NotFoundError,
);
});

Expand Down Expand Up @@ -268,7 +269,7 @@ describe("ZepClient", () => {
uuid: "",
}),
metadata: {},
})
}),
);
});

Expand All @@ -277,7 +278,7 @@ describe("ZepClient", () => {
fetchMock.mockResponseOnce(JSON.stringify({}), { status: 500 });

await expect(client.memory.getMemory("test-session")).rejects.toThrow(
APIError
APIError,
);
});

Expand All @@ -301,9 +302,9 @@ describe("ZepClient", () => {
fetchMock.mockIf(
(req) =>
req.url.startsWith(
`${BASE_URL}/api/v1/sessions/test-session/memory`
`${BASE_URL}/api/v1/sessions/test-session/memory`,
) && req.url.includes("lastn=2"),
JSON.stringify(responseData)
JSON.stringify(responseData),
);

const memory = await client.memory.getMemory("test-session", 2);
Expand All @@ -328,7 +329,7 @@ describe("ZepClient", () => {
token_count: 0,
}),
metadata: {},
})
}),
);
});

Expand All @@ -351,7 +352,7 @@ describe("ZepClient", () => {

const result = await client.memory.addMemory(
"test-session",
memoryData
memoryData,
);

expect(result).toEqual("OK");
Expand All @@ -377,7 +378,7 @@ describe("ZepClient", () => {
fetchMock.mockResponseOnce(JSON.stringify({}), { status: 500 });

await expect(
client.memory.addMemory("test-session", memoryData)
client.memory.addMemory("test-session", memoryData),
).rejects.toThrow(APIError);
});
});
Expand All @@ -400,7 +401,7 @@ describe("ZepClient", () => {
fetchMock.mockResponseOnce(JSON.stringify({}), { status: 404 });

await expect(
client.memory.deleteMemory("test-session")
client.memory.deleteMemory("test-session"),
).rejects.toThrow(NotFoundError);
});

Expand All @@ -409,7 +410,7 @@ describe("ZepClient", () => {
fetchMock.mockResponseOnce(JSON.stringify({}), { status: 500 });

await expect(
client.memory.deleteMemory("test-session")
client.memory.deleteMemory("test-session"),
).rejects.toThrow(APIError);
});
});
Expand Down Expand Up @@ -445,7 +446,7 @@ describe("ZepClient", () => {

const searchResults = await client.memory.searchMemory(
"test-session",
searchPayload
searchPayload,
);

expect(searchResults).toEqual(responseData);
Expand All @@ -462,7 +463,7 @@ describe("ZepClient", () => {
fetchMock.mockResponseOnce(JSON.stringify({}), { status: 404 });

await expect(
client.memory.searchMemory("test-session", searchPayload)
client.memory.searchMemory("test-session", searchPayload),
).rejects.toThrow(NotFoundError);
});

Expand All @@ -477,7 +478,7 @@ describe("ZepClient", () => {
fetchMock.mockResponseOnce(JSON.stringify({}), { status: 500 });

await expect(
client.memory.searchMemory("test-session", searchPayload)
client.memory.searchMemory("test-session", searchPayload),
).rejects.toThrow(APIError);
}); // end it
}); // end describe
Expand Down
2 changes: 1 addition & 1 deletion src/tests/user_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe("client.user", () => {
fetchMock.mockResponses(
JSON.stringify(expectedUsersData[0]),
JSON.stringify(expectedUsersData[1]),
JSON.stringify([]) // empty response to indicate end of list
JSON.stringify([]), // empty response to indicate end of list
);

const usersChunked = [];
Expand Down
6 changes: 3 additions & 3 deletions src/tests/utils_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("Utility functions", () => {
console.warn = jest.fn();
warnDeprecation("testFunction");
expect(console.warn).toHaveBeenCalledWith(
"Warning: testFunction is deprecated and will be removed in the next major release."
"Warning: testFunction is deprecated and will be removed in the next major release.",
);
});

Expand Down Expand Up @@ -54,15 +54,15 @@ describe("Utility functions", () => {
fetchMock.mockResponseOnce("", { status: 404 });

await expect(handleRequest(fetch("/not-found"))).rejects.toThrow(
NotFoundError
NotFoundError,
);
});

test("throws AuthenticationError for 401 status", async () => {
fetchMock.mockResponseOnce("", { status: 401 });

await expect(handleRequest(fetch("/unauthorized"))).rejects.toThrow(
AuthenticationError
AuthenticationError,
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/tests/zep-client_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("ZepClient", () => {

fetchMock.mockResponseOnce((req) => {
expect(req.headers.get("Authorization")).toEqual(
expectedAuthorizationHeader
expectedAuthorizationHeader,
);
return Promise.resolve({
status: 200,
Expand Down
Loading

0 comments on commit 23bb18f

Please sign in to comment.