Skip to content

Commit

Permalink
Update to chat v117.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Jun 11, 2024
1 parent 2696f21 commit 81d1528
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 44 deletions.
2 changes: 1 addition & 1 deletion __tests__/channel-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('channel types CRUD API', () => {

const getResponse = await client.chat.getChannelType({ name: channelType });

// @ts-expect-error typing problem
// Property 'automod' does not exist on type 'Response'.
expect(getResponse.automod).toBe(
CreateChannelTypeRequestAutomodEnum.SIMPLE,
);
Expand Down
7 changes: 5 additions & 2 deletions __tests__/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { v4 as uuidv4 } from 'uuid';
import { createTestClient } from './create-test-client';
import { StreamClient } from '../src/StreamClient';
import { StreamChannel } from '../src/StreamChannel';
import exp from 'constants';

describe('channel API', () => {
let client: StreamClient;
Expand Down Expand Up @@ -35,10 +34,12 @@ describe('channel API', () => {

it('create', async () => {
const response = await channel.getOrCreate({
// Type error: Object literal may only specify known properties, and 'name' does not exist in type 'ChannelInput'.
data: { created_by_id: user.id, name: channelId },
});

expect(response.channel?.cid).toBe(`${channel.type}:${channel.id}`);
// Type error: Property 'name' does not exist on type 'ChannelResponse'
expect(response.channel?.name).toBe(channelId);
});

Expand All @@ -47,6 +48,8 @@ describe('channel API', () => {
const response = await channelWithoutId.getOrCreate({
data: {
created_by_id: user.id,
// Type error: Type '{ user_id: string; }' is missing the following properties from type 'ChannelMember':
// banned, channel_role, created_at, notifications_muted, and 2 more.
members: [{ user_id: user.id }, { user_id: user2.id }],
},
});
Expand Down Expand Up @@ -82,7 +85,7 @@ describe('channel API', () => {
expect(unfilteredResponse.channels.length).toBeGreaterThan(1);

const filteredResponse = await client.chat.queryChannels({
filter_conditions: { id: channelId },
filter_conditions: { cid: channel.cid },
});

expect(filteredResponse.channels.length).toBe(1);
Expand Down
4 changes: 2 additions & 2 deletions __tests__/devices-push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ describe('devices and push', () => {
push_provider_name: 'firebase',
user_id: user.id,
};
// Type '{ name: string; type: string; xiaomi_app_secret: string; xiaomi_package_name: string; }'
// is missing the following properties from type 'PushProvider': created_at, updated_at
const pushProvider: PushProvider = {
name: 'test-push-provider',
type: 'xiaomi',
xiaomi_app_secret: '',
xiaomi_package_name: '',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};

beforeAll(async () => {
Expand Down
4 changes: 4 additions & 0 deletions __tests__/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('messages API', () => {
channel = client.chat.channel('messaging', channelId);
await channel.getOrCreate({
data: {
// Type '{ id: string; }' is missing the following properties from type 'UserObject': banned, custom, online, role
created_by: { id: user.id },
members: [{ user }, { user: user2 }],
},
Expand Down Expand Up @@ -63,9 +64,11 @@ describe('messages API', () => {
const urlAttachment = await channel.getOpenGraphData({
url: 'https://getstream.io/',
});
delete urlAttachment.custom;
const response = await channel.updateMessage(messageId!, {
message: {
text: 'https://getstream.io/',
// Property 'custom' is missing in type '{ image_url: string; }' but required in type 'Attachment'
attachments: [urlAttachment],
user_id: user.id,
},
Expand Down Expand Up @@ -99,6 +102,7 @@ describe('messages API', () => {
language: TranslateMessageRequestLanguageEnum.HU,
});

// Property 'message' does not exist on type 'MessageResponse'.
expect(response.message?.i18n?.hu_text).toBeDefined();
});

Expand Down
9 changes: 9 additions & 0 deletions __tests__/user-compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ describe('user-video compatibility API', () => {
});

it('upsert user', async () => {
const user = {
id: uuidv4(),
role: 'admin',
name: 'Test User for user API compatibily',
custom: {
note: 'compatibilty test',
},
};

const response = await client.upsertUsers({
users: {
[user.id]: { ...user },
Expand Down
33 changes: 31 additions & 2 deletions __tests__/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,43 @@ describe('user API', () => {
expect(muteResponse.mute?.target?.id).toBe(newUser.id);

const unmuteResponse = await client.unmuteUser({
target_id: newUser.id,
target_ids: [],
target_ids: [newUser.id],
user_id: user.id,
});

expect(unmuteResponse).toBeDefined();
});

it('block and unblock', async () => {
const badUser: UserRequest = {
id: 'bad-alice',
name: 'Alice',
};
await client.upsertUsers({ users: { [badUser.id]: badUser } });

const blockResponse = await client.blockUsers({
blocked_user_id: badUser.id,
user_id: user.id,
});

expect(
blockResponse.blocks.find((b) => b.blocked_user_id === badUser.id),
).toBeDefined();

const blockedUsers = await client.getBlockedUsers({ userId: user.id });

expect(
blockedUsers.blocks.find((b) => b.blocked_user_id === badUser.id),
).toBeDefined();

const unblockResponse = await client.unblockUsers({
blocked_user_id: badUser.id,
user_id: user.id,
});

expect(unblockResponse.duration).toBeDefined();
});

it('send custom event', async () => {
const response = await client.sendCustomEventToUser(newUser.id, {
type: 'my-custom-event',
Expand Down
15 changes: 15 additions & 0 deletions src/StreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { StreamVideoClient } from './StreamVideoClient';
import {
APIError,
BanRequest,
BlockUsersRequest,
CheckPushRequest,
CreateDeviceRequest,
CreateGuestRequest,
Expand All @@ -16,6 +17,7 @@ import {
ExportUserRequest,
ExportUsersRequest,
FlagRequest,
GetBlockedUsersRequest,
GetPermissionRequest,
GetTaskRequest,
ListDevicesRequest,
Expand All @@ -28,6 +30,7 @@ import {
ReactivateUsersRequest,
RestoreUsersRequest,
UnbanRequest,
UnblockUsersRequest,
UnmuteUserRequest,
UpdateAppRequest,
UpdateUserPartialRequest,
Expand Down Expand Up @@ -326,6 +329,18 @@ export class StreamClient {
}
};

blockUsers = (blockUsersRequest: BlockUsersRequest) => {
return this.chatApi.blockUsers({ blockUsersRequest });
};

unblockUsers = (unblockUsersRequest: UnblockUsersRequest) => {
return this.chatApi.unblockUsers({ unblockUsersRequest });
};

getBlockedUsers = (request: GetBlockedUsersRequest) => {
return this.chatApi.getBlockedUsers(request);
};

getConfiguration = (product: 'chat' | 'video' = 'chat') => {
return new Configuration({
apiKey: (name: string) => {
Expand Down
16 changes: 12 additions & 4 deletions src/gen/chat/apis/ProductchatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Stream API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: v116.0.2
* The version of the OpenAPI document: v117.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down Expand Up @@ -385,6 +385,10 @@ export interface GetBlockListRequest {
name: string;
}

export interface GetBlockedUsersRequest {
userId?: string;
}

export interface GetCallTokenOperationRequest {
getCallTokenRequest: GetCallTokenRequest | null;
}
Expand Down Expand Up @@ -2863,9 +2867,13 @@ export class ProductchatApi extends runtime.BaseAPI {
* Get list of blocked Users
* Get list of blocked Users
*/
async getBlockedUsersRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<GetBlockedUsersResponse>> {
async getBlockedUsersRaw(requestParameters: GetBlockedUsersRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<GetBlockedUsersResponse>> {
const queryParameters: any = {};

if (requestParameters.userId !== undefined) {
queryParameters['user_id'] = requestParameters.userId;
}

const headerParameters: runtime.HTTPHeaders = {};

if (this.configuration && this.configuration.apiKey) {
Expand Down Expand Up @@ -2894,8 +2902,8 @@ export class ProductchatApi extends runtime.BaseAPI {
* Get list of blocked Users
* Get list of blocked Users
*/
async getBlockedUsers(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<GetBlockedUsersResponse> {
const response = await this.getBlockedUsersRaw(initOverrides);
async getBlockedUsers(requestParameters: GetBlockedUsersRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<GetBlockedUsersResponse> {
const response = await this.getBlockedUsersRaw(requestParameters, initOverrides);
return await response.value();
}

Expand Down
Loading

0 comments on commit 81d1528

Please sign in to comment.