Skip to content

Commit

Permalink
fix: Define mock client using special example URL
Browse files Browse the repository at this point in the history
  • Loading branch information
evrys committed Aug 20, 2024
1 parent feb7b84 commit b26d737
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 19 deletions.
11 changes: 2 additions & 9 deletions src/NovaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type NovaClientConfig = {
* Url of the deployed Nova instance to connect to
* e.g. https://saeattii.instance.wandelbots.io
*/
instanceUrl: string
instanceUrl: string | "https://mock.example.com"

/**
* Identifier of the cell on the Nova instance to connect this client to.
Expand All @@ -30,13 +30,6 @@ export type NovaClientConfig = {
* Password for basic auth to the Nova instance.
*/
password?: string

/**
* EXPERIMENTAL - For testing purposes. If true, the client won't connect to a Nova
* instance at all, and will instead use its own internal, heavily simplified mock replica
* to respond to requests.
*/
mock?: boolean
} & Omit<Configuration, "isJsonMime" | "basePath">

type NovaClientConfigWithDefaults = NovaClientConfig & { cellId: string }
Expand All @@ -57,7 +50,7 @@ export class NovaClient {
...config,
}

if (this.config.mock) {
if (this.config.instanceUrl === "https://mock.example.com") {
this.mock = new MockNovaInstance()
}

Expand Down
3 changes: 1 addition & 2 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { NovaClient } from "../dist"

test("things compile and initialize", async () => {
const nova = new NovaClient({
instanceUrl: "https://nova.mock",
mock: true,
instanceUrl: "https://mock.example.com",
})

expect(nova.config.cellId).toBe("cell")
Expand Down
3 changes: 1 addition & 2 deletions test/jogging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { NovaClient } from "../dist"

test("things compile and initialize", async () => {
const nova = new NovaClient({
instanceUrl: "https://nova.mock",
mock: true,
instanceUrl: "https://mock.example.com",
})
})
5 changes: 2 additions & 3 deletions test/motionStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { NovaClient } from "../dist"

test("motion stream", async () => {
const nova = new NovaClient({
instanceUrl: "https://nova.mock",
mock: true,
instanceUrl: "https://mock.example.com",
})

const motionStream = await nova.connectMotionStream("0@mock-ur5e")
Expand All @@ -20,6 +19,6 @@ test("motion stream", async () => {
await motionStream.motionStateSocket.firstMessage()

expect(motionStream.motionStateSocket.url).toBe(
"wss://nova.mock/api/v1/cells/cell/motion-groups/0@mock-ur5e/state-stream?tcp=foo",
"wss://mock.example.com/api/v1/cells/cell/motion-groups/0@mock-ur5e/state-stream?tcp=foo",
)
})
5 changes: 2 additions & 3 deletions test/websockets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import { NovaClient } from "../dist"

test("websocket handling", async () => {
const nova = new NovaClient({
instanceUrl: "https://nova.mock",
mock: true,
instanceUrl: "https://mock.example.com",
})

// Check that we turn a path into a websocket URL correctly
const ws = nova.openReconnectingWebsocket(
"/motion-groups/0@mock-ur5e/state-stream",
)
expect(ws.url).toBe(
"wss://nova.mock/api/v1/cells/cell/motion-groups/0@mock-ur5e/state-stream",
"wss://mock.example.com/api/v1/cells/cell/motion-groups/0@mock-ur5e/state-stream",
)

// Opening the same websocket again should return the same object
Expand Down

0 comments on commit b26d737

Please sign in to comment.