Skip to content

Commit

Permalink
feat: Upgrade to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Jun 10, 2024
1 parent f6bb146 commit 2696f21
Show file tree
Hide file tree
Showing 11 changed files with 430 additions and 24 deletions.
35 changes: 29 additions & 6 deletions __tests__/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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';

Check failure on line 6 in __tests__/channel.test.ts

View workflow job for this annotation

GitHub Actions / lint

'constants' module was deprecated since v6.3.0. Use 'constants' property of each module instead

Check failure on line 6 in __tests__/channel.test.ts

View workflow job for this annotation

GitHub Actions / lint

'exp' is defined but never used

describe('channel API', () => {
let client: StreamClient;
Expand Down Expand Up @@ -38,16 +39,22 @@ describe('channel API', () => {
});

expect(response.channel?.cid).toBe(`${channel.type}:${channel.id}`);
expect(response.channel?.name).toBe(channelId);
});

// it("create - without id", async () => {
// const channelWithoutId = client.chat.channel('messaging');
// const response = await channelWithoutId.getOrCreate({data: {created_by_id: user.id, members: [{user_id: user.id}, {user_id: user2.id}]}});
it('create - without id', async () => {
const channelWithoutId = client.chat.channel('messaging');
const response = await channelWithoutId.getOrCreate({
data: {
created_by_id: user.id,
members: [{ user_id: user.id }, { user_id: user2.id }],
},
});

// expect(response.channel?.cid).toBe(channelWithoutId.cid);
expect(response.channel?.cid).toBe(channelWithoutId.cid);

// await channelWithoutId.delete();
// });
await channelWithoutId.delete();
});

it('update', async () => {
const response = await channel.update({
Expand All @@ -69,6 +76,22 @@ describe('channel API', () => {
expect(response.channel?.cooldown).toBe(100);
});

it('queryChannels', async () => {
const unfilteredResponse = await client.chat.queryChannels();

expect(unfilteredResponse.channels.length).toBeGreaterThan(1);

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

expect(filteredResponse.channels.length).toBe(1);

const channelFromResponse = filteredResponse.channels[0];

expect(channelFromResponse.channel?.name).toBe(channelId);
});

it('query members', async () => {
const response = await channel.queryMembers({
filter_conditions: {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/external-recording-storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('external storage CRUD API', () => {
const response = await client.video.createExternalStorage({
name: storageName,
bucket: 'test',
storage_type: 'test',
storage_type: 'abs',
});

expect(response).toBeDefined();
Expand All @@ -32,7 +32,7 @@ describe('external storage CRUD API', () => {
const newBucket = 'new bucket';
const response = await client.video.updateExternalStorage(storageName, {
bucket: newBucket,
storage_type: 'test',
storage_type: 'abs',
});

expect(response.bucket).toBe('new bucket');
Expand Down
11 changes: 7 additions & 4 deletions __tests__/user-compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,33 @@ import { StreamClient } from '../src/StreamClient';
describe('user-video compatibility API', () => {
let client: StreamClient;
const user = {
id: 'stream-node-test-user',
id: uuidv4(),
role: 'admin',
name: 'Test User for user API compatibily',
custom: {
note: 'compatibilty test',
},
};

beforeAll(async () => {
beforeAll(() => {
client = createTestClient();
});

it('upsert user', async () => {
const response = await client.upsertUsers({
users: {
[user.id]: { ...user },
},
});

console.log(response.users[user.id].custom);
expect(response.users[user.id].custom.note).toBe('compatibilty test');
});

it('create call', async () => {
const call = client.video.call('default', uuidv4());
const response = await call.create({ data: { created_by: user } });

console.log(response.call.created_by);
// Backend returns: {custom: { custom: { note: 'compatibilty test' } }}
expect(response.call.created_by.custom.note).toBe('compatibilty test');
expect(response.call.created_by.name).toBe(
'Test User for user API compatibily',
Expand Down
18 changes: 11 additions & 7 deletions src/StreamChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ export class StreamChannel {
channelGetOrCreateRequest: channelGetOrCreateRequest ?? {},
});
} else {
throw new Error(`This operation isn't yet implemented`);
// if (!channelGetOrCreateRequest?.data?.members) {
// throw new Error('You need to provide members to create a channel without ID');
// }
// const response = await this.chatApi.getOrCreateChannelType1({type: this.type, channelGetOrCreateRequest});
// this.id = response.channel?.id;
// return response;
if (!channelGetOrCreateRequest?.data?.members) {
throw new Error(
'You need to provide members to create a channel without ID',
);
}
const response = await this.chatApi.getOrCreateDistinctChannel({
type: this.type,
channelGetOrCreateRequest,
});
this.id = response.channel?.id;
return response;
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/StreamChatClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class StreamChatClient {

queryChannels = (queryChannelsRequest?: QueryChannelsRequest) => {
return this.chatApi.queryChannels({
queryChannelsRequest: queryChannelsRequest ?? null,
queryChannelsRequest: queryChannelsRequest ?? {},
});
};

Expand Down
149 changes: 148 additions & 1 deletion 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.0
* The version of the OpenAPI document: v116.0.2
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -17,6 +17,8 @@ import * as runtime from '../runtime';
import type {
APIError,
BanRequest,
BlockUsersRequest,
BlockUsersResponse,
CastPollVoteRequest,
ChannelGetOrCreateRequest,
ChannelStateResponse,
Expand Down Expand Up @@ -71,6 +73,7 @@ import type {
FlagResponse,
GetApplicationResponse,
GetBlockListResponse,
GetBlockedUsersResponse,
GetCallTokenRequest,
GetCallTokenResponse,
GetCommandResponse,
Expand Down Expand Up @@ -153,6 +156,8 @@ import type {
TranslateMessageRequest,
TruncateChannelRequest,
TruncateChannelResponse,
UnblockUsersRequest,
UnblockUsersResponse,
UnmuteChannelRequest,
UnmuteResponse,
UnmuteUserRequest,
Expand Down Expand Up @@ -191,6 +196,10 @@ export interface BanOperationRequest {
banRequest: BanRequest | null;
}

export interface BlockUsersOperationRequest {
blockUsersRequest: BlockUsersRequest | null;
}

export interface CastPollVoteOperationRequest {
messageId: string;
pollId: string;
Expand Down Expand Up @@ -637,6 +646,10 @@ export interface UnbanRequest {
createdBy?: string;
}

export interface UnblockUsersOperationRequest {
unblockUsersRequest: UnblockUsersRequest | null;
}

export interface UndeleteMessageRequest {
id: string;
updateMessageRequest: UpdateMessageRequest | null;
Expand Down Expand Up @@ -798,6 +811,53 @@ export class ProductchatApi extends runtime.BaseAPI {
return await response.value();
}

/**
* Block users
* Block user
*/
async blockUsersRaw(requestParameters: BlockUsersOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<BlockUsersResponse>> {
if (requestParameters.blockUsersRequest === null || requestParameters.blockUsersRequest === undefined) {
throw new runtime.RequiredError('blockUsersRequest','Required parameter requestParameters.blockUsersRequest was null or undefined when calling blockUsers.');
}

const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

headerParameters['Content-Type'] = 'application/json';

if (this.configuration && this.configuration.apiKey) {
headerParameters["Stream-Auth-Type"] = this.configuration.apiKey("Stream-Auth-Type"); // stream-auth-type authentication
}

if (this.configuration && this.configuration.apiKey) {
queryParameters["api_key"] = this.configuration.apiKey("api_key"); // api_key authentication
}

if (this.configuration && this.configuration.apiKey) {
headerParameters["Authorization"] = this.configuration.apiKey("Authorization"); // JWT authentication
}

const response = await this.request({
path: `/users/block`,
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: requestParameters.blockUsersRequest,
}, initOverrides);

return new runtime.JSONApiResponse(response);
}

/**
* Block users
* Block user
*/
async blockUsers(requestParameters: BlockUsersOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<BlockUsersResponse> {
const response = await this.blockUsersRaw(requestParameters, initOverrides);
return await response.value();
}

/**
* Cast a vote on a poll Sends events: - poll.vote_casted Required permissions: - CastVote
* Cast vote
Expand Down Expand Up @@ -2799,6 +2859,46 @@ export class ProductchatApi extends runtime.BaseAPI {
return await response.value();
}

/**
* Get list of blocked Users
* Get list of blocked Users
*/
async getBlockedUsersRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<GetBlockedUsersResponse>> {
const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

if (this.configuration && this.configuration.apiKey) {
headerParameters["Stream-Auth-Type"] = this.configuration.apiKey("Stream-Auth-Type"); // stream-auth-type authentication
}

if (this.configuration && this.configuration.apiKey) {
queryParameters["api_key"] = this.configuration.apiKey("api_key"); // api_key authentication
}

if (this.configuration && this.configuration.apiKey) {
headerParameters["Authorization"] = this.configuration.apiKey("Authorization"); // JWT authentication
}

const response = await this.request({
path: `/users/block`,
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);

return new runtime.JSONApiResponse(response);
}

/**
* Get list of blocked Users
* Get list of blocked Users
*/
async getBlockedUsers(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<GetBlockedUsersResponse> {
const response = await this.getBlockedUsersRaw(initOverrides);
return await response.value();
}

/**
* Retrieves the token to join a call Required permissions: - JoinCall - ReadChannel
* Get Call Token
Expand Down Expand Up @@ -5654,6 +5754,53 @@ export class ProductchatApi extends runtime.BaseAPI {
return await response.value();
}

/**
* Unblock users
* Unblock user
*/
async unblockUsersRaw(requestParameters: UnblockUsersOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<UnblockUsersResponse>> {
if (requestParameters.unblockUsersRequest === null || requestParameters.unblockUsersRequest === undefined) {
throw new runtime.RequiredError('unblockUsersRequest','Required parameter requestParameters.unblockUsersRequest was null or undefined when calling unblockUsers.');
}

const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

headerParameters['Content-Type'] = 'application/json';

if (this.configuration && this.configuration.apiKey) {
headerParameters["Stream-Auth-Type"] = this.configuration.apiKey("Stream-Auth-Type"); // stream-auth-type authentication
}

if (this.configuration && this.configuration.apiKey) {
queryParameters["api_key"] = this.configuration.apiKey("api_key"); // api_key authentication
}

if (this.configuration && this.configuration.apiKey) {
headerParameters["Authorization"] = this.configuration.apiKey("Authorization"); // JWT authentication
}

const response = await this.request({
path: `/users/unblock`,
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: requestParameters.unblockUsersRequest,
}, initOverrides);

return new runtime.JSONApiResponse(response);
}

/**
* Unblock users
* Unblock user
*/
async unblockUsers(requestParameters: UnblockUsersOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<UnblockUsersResponse> {
const response = await this.unblockUsersRaw(requestParameters, initOverrides);
return await response.value();
}

/**
* Undelete a message that was previously soft-deleted Sends events: - message.undeleted
* Undelete message
Expand Down
Loading

0 comments on commit 2696f21

Please sign in to comment.