Skip to content

Commit

Permalink
feat: update to latest open api - in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed May 31, 2024
1 parent 52a1ff4 commit 1446a31
Show file tree
Hide file tree
Showing 38 changed files with 12,183 additions and 15,343 deletions.
18 changes: 0 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,6 @@ $ PRODUCT=video yarn generate:open-api
$ PRODUCT=chat yarn generate:open-api:dev
```

### Fix issues in chat code

If you have updated the generated chat code you'll have to fix the following issues manually in the generated code:

- Add `/** @ts-expect-error */ ` (make sure to use this exact comment format otherwise they will be missing from `d.ts` files) for imports for `ImageSizeRequest`, `OnlyUserIDRequest` in the `gen/chat/FilesApi.ts` and `gen/chat/MessagesApi.ts` files
- Add `/** @ts-expect-error */ ` (make sure to use this exact comment format otherwise they will be missing from `d.ts` files) for duplicate exports in `gen/chat/index.ts`

### Validate that the generated code works

To check your work, run the following commands:

```
yarn start
yarn test
```

If these commands run fine, we're good to go.

## Release (for Stream developers)

Releasing this package involves two GitHub Action steps:
Expand Down
8 changes: 6 additions & 2 deletions __tests__/block-lists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ import { beforeAll, describe, expect, it } from 'vitest';
import { v4 as uuidv4 } from 'uuid';
import { createTestClient } from './create-test-client';
import { StreamClient } from '../src/StreamClient';
import { BlockList } from '../src/gen/chat';
import {
CreateBlockListRequest,
CreateBlockListRequestTypeEnum,
} from '../src/gen/chat';

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

beforeAll(() => {
client = createTestClient();
blockList = {
name: 'streamnodetest-F1' + uuidv4(),
words: ['Ricciardo should retire'],
type: CreateBlockListRequestTypeEnum.WORD,
};
});

Expand Down
4 changes: 4 additions & 0 deletions __tests__/channel-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('channel types CRUD API', () => {
const response = await client.chat.createChannelType({
name: channelType,
automod: CreateChannelTypeRequestAutomodEnum.DISABLED,
automod_behavior: 'block',
max_message_length: 1200,
});

expect(response.name).toBe(channelType);
Expand All @@ -30,6 +32,8 @@ describe('channel types CRUD API', () => {
it('update', async () => {
const response = await client.chat.updateChannelType(channelType, {
automod: CreateChannelTypeRequestAutomodEnum.SIMPLE,
automod_behavior: 'block',
max_message_length: 1200,
});

expect(response.automod).toBe(CreateChannelTypeRequestAutomodEnum.SIMPLE);
Expand Down
8 changes: 5 additions & 3 deletions __tests__/devices-push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { v4 as uuidv4 } from 'uuid';
import {
CreateDeviceRequest,
CreateDeviceRequestPushProviderEnum,
PushProviderRequest,
PushProvider,
} from '../src/gen/chat';
import { createTestClient } from './create-test-client';
import { StreamClient } from '../src/StreamClient';
Expand All @@ -20,11 +20,13 @@ describe('devices and push', () => {
push_provider_name: 'firebase',
user_id: user.id,
};
const pushProvider: PushProviderRequest = {
const pushProvider: PushProvider = {
name: 'test-push-provider',
type: 'xiaomi' as any as number,
type: 'xiaomi',
xiaomi_app_secret: '',
xiaomi_package_name: '',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};

beforeAll(async () => {
Expand Down
9 changes: 1 addition & 8 deletions __tests__/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,13 @@ describe('messages API', () => {
expect(response.results).toBeDefined();
});

it('flag and unflag', async () => {
it('flag', async () => {
const response = await client.flag({
target_message_id: messageId!,
user_id: user.id,
});

expect(response.flag?.target_message_id).toBe(messageId!);

const unflagResponse = await client.unflag({
target_message_id: messageId!,
user_id: user.id,
});

expect(unflagResponse).toBeDefined();
});

it('truncate', async () => {
Expand Down
5 changes: 4 additions & 1 deletion __tests__/user-compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ describe('user-video compatibility API', () => {

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

console.log(response.users[user.id].custom);
});

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);
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
10 changes: 6 additions & 4 deletions __tests__/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { beforeAll, describe, expect, it } from 'vitest';
import { v4 as uuidv4 } from 'uuid';
import { createTestClient } from './create-test-client';
import { StreamClient } from '../src/StreamClient';
import { UserObjectRequest } from '../src/gen/chat';
import { UserRequest } from '../src/gen/chat';

describe('user API', () => {
let client: StreamClient;
const userId = 'streamnodetest' + uuidv4();
const newUser: UserObjectRequest = {
const newUser: UserRequest = {
id: userId,
role: 'user',
custom: {
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('user API', () => {
it('create guest', async () => {
await client.updateAppSettings({ multi_tenant_enabled: false });

const guest: UserObjectRequest = {
const guest: UserRequest = {
id: uuidv4(),
custom: {
color: 'red',
Expand Down Expand Up @@ -155,7 +155,9 @@ describe('user API', () => {
id: newUser.id,
set: {
role: 'admin',
color: 'blue',
custom: {
color: 'blue',
},
},
unset: ['name'],
},
Expand Down
4 changes: 3 additions & 1 deletion generate-openapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ if [ "$PRODUCT" == 'chat' ] || [ "$PRODUCT" == 'all' ]; then
--additional-properties=supportsES6=true \
--additional-properties=modelPropertyNaming=original \
--additional-properties=enumPropertyNaming=UPPERCASE \
--additional-properties=withoutRuntimeChecks=true
--additional-properties=withoutRuntimeChecks=true \
--global-property=skipFormModel=false \
--skip-validate-spec

# Remove the generated API client, just keep the models
cp -r $TEMP_OUTPUT_DIR/ $OUTPUT_DIR
Expand Down
Loading

0 comments on commit 1446a31

Please sign in to comment.