Skip to content

Commit

Permalink
fixed tests, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
matthme committed Apr 26, 2024
1 parent 07a13f8 commit b797ff4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export { hashZomeCall } from "@holochain/serialization";
export * from "./admin/index.js";
export * from "./app/index.js";
export { IsoWebSocket, WsClient, type AppAuthenticationRequest } from "./client.js";
export {
IsoWebSocket,
WsClient,
type AppAuthenticationRequest,
} from "./client.js";
export {
CloneId,
HolochainError,
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/app-websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,18 @@ test(
installed_app_id: app_id1,
});
const clientUrl = new URL(`ws://localhost:${appPort}`);
const appWs1 = await AppWebsocket.connect(issued1.token, {
const appWs1 = await AppWebsocket.connect({
url: clientUrl,
wsClientOptions: { origin: "client-test-app" },
token: issued1.token,
});
const issued2 = await admin.issueAppAuthenticationToken({
installed_app_id: app_id2,
});
const appWs2 = await AppWebsocket.connect(issued2.token, {
const appWs2 = await AppWebsocket.connect({
url: clientUrl,
wsClientOptions: { origin: "client-test-app" },
token: issued2.token,
});

appWs1.on("signal", signalCb1);
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ export const installAppAndDna = async (
const issued = await admin.issueAppAuthenticationToken({
installed_app_id,
});
const client = await AppWebsocket.connect(issued.token, {
const client = await AppWebsocket.connect({
url: new URL(`ws://localhost:${appPort}`),
wsClientOptions: { origin: "client-test-app" },
token: issued.token,
});
return { installed_app_id, cell_id, client, admin };
};
Expand Down Expand Up @@ -160,10 +161,11 @@ export const createAppWsAndInstallApp = async (
const issued = await admin.issueAppAuthenticationToken({
installed_app_id,
});
const client = await AppWebsocket.connect(issued.token, {
const client = await AppWebsocket.connect({
url: new URL(`ws://localhost:${appPort}`),
wsClientOptions: { origin: "client-test-app" },
defaultTimeout: 12000,
token: issued.token,
});
return { installed_app_id, cell_id, client, admin };
};
Expand Down
17 changes: 11 additions & 6 deletions test/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,10 @@ test(
const issued = await admin.issueAppAuthenticationToken({
installed_app_id,
});
await AppWebsocket.connect(issued.token, {
await AppWebsocket.connect({
url: new URL(`ws://localhost:${port}`),
wsClientOptions: { origin: "client-test-app" },
token: issued.token,
});
t.pass("can connect an app websocket to attached port");
})
Expand All @@ -410,9 +411,10 @@ test(
installed_app_id,
});
try {
await AppWebsocket.connect(issued.token, {
await AppWebsocket.connect({
url: new URL(`ws://localhost:${port}`),
wsClientOptions: { origin: allowedOrigin },
token: issued.token,
});
t.pass("app websocket connection established");
} catch (error) {
Expand All @@ -432,9 +434,10 @@ test(
installed_app_id,
});
try {
await AppWebsocket.connect(issued.token, {
await AppWebsocket.connect({
url: new URL(`ws://localhost:${port}`),
wsClientOptions: { origin: "disallowed_origin" },
token: issued.token,
});
t.fail("app websocket connection should have failed");
} catch (error) {
Expand Down Expand Up @@ -531,9 +534,10 @@ test(
const issued = await admin.issueAppAuthenticationToken({
installed_app_id,
});
const client = await AppWebsocket.connect(issued.token, {
const client = await AppWebsocket.connect({
url: new URL(`ws://localhost:${appPort}`),
wsClientOptions: { origin: "client-test-app" },
token: issued.token,
});

assert(CellType.Provisioned in app.cell_info[role_name][0]);
Expand Down Expand Up @@ -601,9 +605,10 @@ test(
const issued = await admin.issueAppAuthenticationToken({
installed_app_id,
});
const client = await AppWebsocket.connect(issued.token, {
const client = await AppWebsocket.connect({
url: new URL(`ws://localhost:${appPort}`),
wsClientOptions: { origin: "client-test-app" },
token: issued.token,
});

assert(CellType.Provisioned in app.cell_info[role_name][0]);
Expand Down Expand Up @@ -701,7 +706,7 @@ test("error is catchable when holochain socket is unavailable", async (t) => {
}

try {
await AppWebsocket.connect([], { url: ADMIN_WS_URL });
await AppWebsocket.connect({ url: ADMIN_WS_URL });
t.fail("websocket connection should have failed");
} catch (e) {
t.assert(e instanceof HolochainError, "expected a HolochainError");
Expand Down

0 comments on commit b797ff4

Please sign in to comment.