Skip to content

Commit 2f6b87f

Browse files
committed
example: test setup
1 parent fe4bae2 commit 2f6b87f

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

.github/workflows/workflow.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
- master
66
- angular-19
77
- test-update
8+
- channel-service-extra-logs
89
pull_request:
910
branches:
1011
- master
@@ -53,10 +54,8 @@ jobs:
5354
env:
5455
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
5556
VERCEL_PROJECT_ID: ${{ vars.VERCEL_PROJECT_ID }}
56-
STREAM_API_KEY: ${{ vars.STREAM_DEMO_API_KEY }}
57-
STREAM_TOKEN_URL: ${{ vars.STREAM_DEMO_TOKEN_URL }}
58-
STREAM_USER_ID: <dynamic user>
59-
STREAM_CHANNELS_FILTER: '{"type": "messaging", "id": "talking-about-angular"}'
57+
STREAM_API_KEY: ${{ vars.TEST_APP_API_KEY }}
58+
STREAM_TOKEN_URL: ${{ vars.TEST_APP_TOKEN_URL }}
6059
run: >
6160
yarn vercel pull --yes --environment=${{ github.ref == 'refs/heads/master' && 'production' || 'preview' }} --token=${{ secrets.VERCEL_TOKEN }} &&
6261
yarn vercel build ${{ github.ref == 'refs/heads/master' && '--prod' || '' }} --token=${{ secrets.VERCEL_TOKEN }} &&

projects/sample-app/src/app/app.component.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,12 @@ export class AppComponent implements AfterViewInit, OnDestroy {
4343
private customTemplateService: CustomTemplatesService,
4444
themeService: ThemeService
4545
) {
46-
const isDynamicUser = environment.userId === '<dynamic user>';
47-
const userId = isDynamicUser ? uuidv4() : environment.userId;
46+
const urlParams = new URLSearchParams(window.location.search);
47+
const userId = urlParams.get('user') ?? '';
4848
void this.chatService.init(
4949
environment.apiKey,
50-
isDynamicUser ? { id: userId, name: names.random() } : userId,
51-
environment.tokenUrl
52-
? async () => {
53-
const url = environment.tokenUrl.replace(
54-
environment.userId,
55-
userId
56-
);
57-
const response = await fetch(url);
58-
const body = (await response.json()) as { token: string };
59-
60-
return body.token;
61-
}
62-
: environment.userToken,
50+
userId,
51+
this.getTokenGenerator(userId),
6352
{
6453
timeout: 10000,
6554
logger: (
@@ -88,11 +77,11 @@ export class AppComponent implements AfterViewInit, OnDestroy {
8877
}
8978
);
9079
void this.channelService.init(
91-
environment.channelsFilter || {
80+
{
9281
type: 'messaging',
9382
members: { $in: [environment.userId] },
9483
},
95-
undefined,
84+
{ has_unread: -1 },
9685
{ limit: 10 }
9786
);
9887
this.subscriptions.push(
@@ -141,6 +130,19 @@ export class AppComponent implements AfterViewInit, OnDestroy {
141130
.subscribe((isThreadOpen) => (this.isThreadOpen = isThreadOpen));
142131
this.theme$ = themeService.theme$;
143132
}
133+
134+
getTokenGenerator(userId: string) {
135+
const oneDay = 24 * 60 * 60;
136+
return async () => {
137+
const response = await fetch(
138+
`${environment.tokenUrl}&user_id=${userId}&exp=${oneDay}`
139+
);
140+
const body = await response.json();
141+
142+
return body.token as string;
143+
};
144+
}
145+
144146
ngOnDestroy(): void {
145147
this.subscriptions.forEach((s) => s.unsubscribe());
146148
}

0 commit comments

Comments
 (0)