-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restore timeout to be 3000ms, use 7500ms timeout for tests
- Loading branch information
Showing
15 changed files
with
142 additions
and
138 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
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
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,9 @@ | ||
import "dotenv/config"; | ||
import { StreamClient } from "../src/StreamClient"; | ||
|
||
const apiKey = process.env.STREAM_API_KEY!; | ||
const secret = process.env.STREAM_SECRET!; | ||
|
||
export const createTestClient = () => { | ||
return new StreamClient(apiKey, secret, undefined, { timeout: 7500 }); | ||
}; |
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,75 +1,83 @@ | ||
import "dotenv/config"; | ||
import { beforeAll, describe, expect, it } from "vitest"; | ||
import { CreateDeviceRequest, CreateDeviceRequestPushProviderEnum, StreamClient, UpsertPushProviderRequest, UserObjectRequest } from ".."; | ||
import { | ||
CreateDeviceRequest, | ||
CreateDeviceRequestPushProviderEnum, | ||
StreamClient, | ||
} from ".."; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { PushProviderRequest } from "../src/gen/chat"; | ||
import { createTestClient } from "./create-test-client"; | ||
|
||
const apiKey = process.env.STREAM_API_KEY!; | ||
const secret = process.env.STREAM_SECRET!; | ||
describe("devices and push", () => { | ||
let client: StreamClient; | ||
const user = { | ||
id: "stream-node-test-user", | ||
role: "admin", | ||
}; | ||
const device: CreateDeviceRequest = { | ||
id: uuidv4(), | ||
push_provider: CreateDeviceRequestPushProviderEnum.FIREBASE, | ||
push_provider_name: "firebase", | ||
user_id: user.id, | ||
}; | ||
const pushProvider: PushProviderRequest = { | ||
name: "test-push-provider", | ||
type: "xiaomi" as any as number, | ||
xiaomi_app_secret: "", | ||
xiaomi_package_name: "", | ||
}; | ||
|
||
describe('devices and push', () => { | ||
let client: StreamClient; | ||
const user = { | ||
id: "stream-node-test-user", | ||
role: "admin", | ||
}; | ||
const device: CreateDeviceRequest = { | ||
id: uuidv4(), | ||
push_provider: CreateDeviceRequestPushProviderEnum.FIREBASE, | ||
push_provider_name: 'firebase', | ||
user_id: user.id | ||
} | ||
const pushProvider: PushProviderRequest = { | ||
name: 'test-push-provider', | ||
type: 'xiaomi' as any as number, | ||
xiaomi_app_secret: '', | ||
xiaomi_package_name: '' | ||
} | ||
|
||
beforeAll(async () => { | ||
client = new StreamClient(apiKey, secret); | ||
await client.upsertUsers({ | ||
users: { | ||
[user.id]: { ...user }, | ||
}, | ||
}); | ||
beforeAll(async () => { | ||
client = createTestClient(); | ||
await client.upsertUsers({ | ||
users: { | ||
[user.id]: { ...user }, | ||
}, | ||
}); | ||
}); | ||
|
||
it('create device', async () => { | ||
expect(async () => await client.createDevice(device)).not.toThrowError(); | ||
}); | ||
it("create device", async () => { | ||
expect(async () => await client.createDevice(device)).not.toThrowError(); | ||
}); | ||
|
||
it('list devices', async () => { | ||
const response = await client.listDevices({userId: user.id}); | ||
it("list devices", async () => { | ||
const response = await client.listDevices({ userId: user.id }); | ||
|
||
expect(response.devices.find(d => d.id === device.id)).toBeDefined(); | ||
}) | ||
expect(response.devices.find((d) => d.id === device.id)).toBeDefined(); | ||
}); | ||
|
||
it('delete device', async () => { | ||
const response = await client.deleteDevice({id: device.id, userId: user.id}); | ||
it("delete device", async () => { | ||
const response = await client.deleteDevice({ | ||
id: device.id, | ||
userId: user.id, | ||
}); | ||
|
||
expect(response).toBeDefined(); | ||
}) | ||
expect(response).toBeDefined(); | ||
}); | ||
|
||
it('create push provider', async () => { | ||
// Can't properly test upsert without valid credentials | ||
await expect(() => client.upsertPushProvider(pushProvider)).rejects.toThrowError('Stream error code 4: UpsertPushProvider failed with error: "xiaomi credentials are invalid"'); | ||
}); | ||
it("create push provider", async () => { | ||
// Can't properly test upsert without valid credentials | ||
await expect(() => | ||
client.upsertPushProvider(pushProvider) | ||
).rejects.toThrowError( | ||
'Stream error code 4: UpsertPushProvider failed with error: "xiaomi credentials are invalid"' | ||
); | ||
}); | ||
|
||
it('list push provider', async () => { | ||
const response = await client.listPushProviders(); | ||
it("list push provider", async () => { | ||
const response = await client.listPushProviders(); | ||
|
||
expect(response.push_providers).toBeDefined(); | ||
}); | ||
expect(response.push_providers).toBeDefined(); | ||
}); | ||
|
||
it('test push provider', async () => { | ||
const response = await client.checkPush({user_id: user.id}); | ||
it("test push provider", async () => { | ||
const response = await client.checkPush({ user_id: user.id }); | ||
|
||
expect(response).toBeDefined(); | ||
}) | ||
expect(response).toBeDefined(); | ||
}); | ||
|
||
// TODO: can't test delete because we can't upsert | ||
// it('delete push provider', async () => { | ||
// const response = await client.deletePushProvider({name: pushProvider.push_provider!.name, type: DeletePushProviderTypeEnum.FIREBASE}); | ||
// }); | ||
}); | ||
// TODO: can't test delete because we can't upsert | ||
// it('delete push provider', async () => { | ||
// const response = await client.deletePushProvider({name: pushProvider.push_provider!.name, type: DeletePushProviderTypeEnum.FIREBASE}); | ||
// }); | ||
}); |
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
Oops, something went wrong.