Skip to content

Commit

Permalink
restore timeout to be 3000ms, use 7500ms timeout for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Nov 7, 2023
1 parent c8896ba commit 66bac0a
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 138 deletions.
7 changes: 2 additions & 5 deletions __tests__/block-lists.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import "dotenv/config";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { BlockList, StreamClient } from "../";
import { v4 as uuidv4 } from "uuid";

const apiKey = process.env.STREAM_API_KEY!;
const secret = process.env.STREAM_SECRET!;
import { createTestClient } from "./create-test-client";

describe("block lists CRUD API", () => {
let client: StreamClient;
let blockList: BlockList;

beforeAll(() => {
client = new StreamClient(apiKey, secret);
client = createTestClient();
blockList = {
name: "streamnodetest-F1" + uuidv4(),
words: ["Ricciardo should retire"],
Expand Down
18 changes: 12 additions & 6 deletions __tests__/call-members.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import "dotenv/config";
import { beforeAll, describe, expect, it } from "vitest";
import { v4 as uuidv4 } from "uuid";
import { StreamCall, StreamClient, VideoOwnCapability } from "../";

const apiKey = process.env.STREAM_API_KEY!;
const secret = process.env.STREAM_SECRET!;
import { createTestClient } from "./create-test-client";

describe("call members API", () => {
let client: StreamClient;
const callId = `call${uuidv4()}`;
let call: StreamCall;

beforeAll(() => {
client = new StreamClient(apiKey, secret);
beforeAll(async () => {
client = createTestClient();

call = client.video.call("default", callId);

await client.upsertUsers({
users: {
john: { name: "John", id: "john" },
jack: { name: "Jack", id: "jack" },
jane: { name: "Jane", id: "jane" },
sara: { name: "Sara", id: "sara" },
},
});
});

it("create with members", async () => {
Expand Down
7 changes: 2 additions & 5 deletions __tests__/call-types.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "dotenv/config";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { v4 as uuidv4 } from "uuid";
import {
Expand All @@ -8,16 +7,14 @@ import {
VideoRecordSettingsRequestModeEnum,
VideoRecordSettingsRequestQualityEnum,
} from "../";

const apiKey = process.env.STREAM_API_KEY!;
const secret = process.env.STREAM_SECRET!;
import { createTestClient } from "./create-test-client";

describe("call types CRUD API", () => {
let client: StreamClient;
const callTypeName = `streamnodetest${uuidv4()}`;

beforeAll(() => {
client = new StreamClient(apiKey, secret);
client = createTestClient();
});

it("create", async () => {
Expand Down
15 changes: 9 additions & 6 deletions __tests__/call.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "dotenv/config";
import { beforeAll, describe, expect, it } from "vitest";
import { v4 as uuidv4 } from "uuid";
import {
Expand All @@ -7,19 +6,23 @@ import {
VideoRecordSettingsRequestModeEnum,
VideoRecordSettingsRequestQualityEnum,
} from "../";

const apiKey = process.env.STREAM_API_KEY!;
const secret = process.env.STREAM_SECRET!;
import { createTestClient } from "./create-test-client";

describe("call API", () => {
let client: StreamClient;
const callId = `call${uuidv4()}`;
let call: StreamCall;

beforeAll(() => {
client = new StreamClient(apiKey, secret);
beforeAll(async () => {
client = createTestClient();

call = client.video.call("default", callId);

await client.upsertUsers({
users: {
john: { name: "John", id: "john" },
},
});
});

it("create", async () => {
Expand Down
32 changes: 16 additions & 16 deletions __tests__/channel-types.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import "dotenv/config";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { v4 as uuidv4 } from "uuid";
import { CreateChannelTypeRequestAutomodEnum, StreamClient } from "../";

const apiKey = process.env.STREAM_API_KEY!;
const secret = process.env.STREAM_SECRET!;
import { createTestClient } from "./create-test-client";

describe("channel types CRUD API", () => {
let client: StreamClient;
const channelType = "streamnodetest" + uuidv4();

beforeAll(() => {
client = new StreamClient(apiKey, secret);
client = createTestClient();
});

it("create", async () => {
Expand Down Expand Up @@ -49,16 +46,19 @@ describe("channel types CRUD API", () => {
expect(response).toBeDefined();
});

afterAll(async () => {
const channelTypes = (await client.chat.listChannelTypes()).channel_types;
const customChannelTypes = Object.keys(channelTypes).filter((type) =>
type.startsWith("streamnodetest")
);
// TODO: why does this doesn't work?
// afterAll(async () => {
// await new Promise((resolve) => setTimeout(resolve, 5000));

await Promise.all(
customChannelTypes.map((t) =>
client.chat.deleteChannelType({ name: channelType })
)
);
});
// const channelTypes = (await client.chat.listChannelTypes()).channel_types;
// const customChannelTypes = Object.keys(channelTypes).filter((type) =>
// type.startsWith("streamnodetest")
// );

// await Promise.all(
// customChannelTypes.map((t) =>
// client.chat.deleteChannelType({ name: channelType })
// )
// );
// });
});
7 changes: 2 additions & 5 deletions __tests__/channel.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import "dotenv/config";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { v4 as uuidv4 } from "uuid";
import { StreamClient, StreamChannel } from "../";

const apiKey = process.env.STREAM_API_KEY!;
const secret = process.env.STREAM_SECRET!;
import { createTestClient } from "./create-test-client";

describe("channel API", () => {
let client: StreamClient;
Expand All @@ -22,7 +19,7 @@ describe("channel API", () => {
};

beforeAll(async () => {
client = new StreamClient(apiKey, secret);
client = createTestClient();

await client.upsertUsers({
users: {
Expand Down
7 changes: 2 additions & 5 deletions __tests__/command.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import "dotenv/config";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { v4 as uuidv4 } from "uuid";
import { StreamClient } from "../";

const apiKey = process.env.STREAM_API_KEY!;
const secret = process.env.STREAM_SECRET!;
import { createTestClient } from "./create-test-client";

describe("commands CRUD API", () => {
let client: StreamClient;
const commandName = "stream-node-test-command" + uuidv4();

beforeAll(() => {
client = new StreamClient(apiKey, secret);
client = createTestClient();
});

it("create", async () => {
Expand Down
9 changes: 9 additions & 0 deletions __tests__/create-test-client.ts
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 });
};
4 changes: 2 additions & 2 deletions __tests__/create-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import "dotenv/config";
import jwt from "jsonwebtoken";
import { beforeAll, describe, expect, it } from "vitest";
import { StreamClient } from "../src/StreamClient";
import { createTestClient } from "./create-test-client";

const apiKey = process.env.STREAM_API_KEY!;
const secret = process.env.STREAM_SECRET!;

describe("creating tokens", () => {
let client: StreamClient;
const userId = "john";

beforeAll(() => {
client = new StreamClient(apiKey, secret);
client = createTestClient();
});

it("with default expiration", () => {
Expand Down
124 changes: 66 additions & 58 deletions __tests__/devices-push.test.ts
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});
// });
});
7 changes: 2 additions & 5 deletions __tests__/messages.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import "dotenv/config";
import { beforeAll, describe, expect, it } from "vitest";
import { v4 as uuidv4 } from "uuid";
import {
StreamClient,
StreamChannel,
TranslateMessageRequestLanguageEnum,
} from "../";

const apiKey = process.env.STREAM_API_KEY!;
const secret = process.env.STREAM_SECRET!;
import { createTestClient } from "./create-test-client";

describe("messages API", () => {
let client: StreamClient;
Expand All @@ -27,7 +24,7 @@ describe("messages API", () => {
let messageId: string | undefined;

beforeAll(async () => {
client = new StreamClient(apiKey, secret);
client = createTestClient();

await client.upsertUsers({
users: {
Expand Down
Loading

0 comments on commit 66bac0a

Please sign in to comment.