Skip to content

Commit 0f15669

Browse files
committed
wip 1
1 parent 1d767d7 commit 0f15669

File tree

9 files changed

+63
-42
lines changed

9 files changed

+63
-42
lines changed

integration/presets/envs.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ const withSessionTasksResetPassword = base
165165
const withBillingJwtV2 = base
166166
.clone()
167167
.setId('withBillingJwtV2')
168-
.setEnvVariable('private', 'CLERK_API_URL', 'https://api.clerkstage.dev')
169-
.setEnvVariable('private', 'CLERK_SECRET_KEY', instanceKeys.get('with-billing-staging').sk)
170-
.setEnvVariable('public', 'CLERK_PUBLISHABLE_KEY', instanceKeys.get('with-billing-staging').pk);
168+
.setEnvVariable('private', 'CLERK_SECRET_KEY', instanceKeys.get('with-billing').sk)
169+
.setEnvVariable('public', 'CLERK_PUBLISHABLE_KEY', instanceKeys.get('with-billing').pk);
171170

172171
const withBilling = base
173172
.clone()

integration/presets/longRunningApps.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ export const createLongRunningApps = () => {
4242
* Billing apps
4343
*/
4444
{ id: 'withBillingJwtV2.next.appRouter', config: next.appRouter, env: envs.withBillingJwtV2 },
45-
{ id: 'withBilling.next.appRouter', config: next.appRouter, env: envs.withBilling },
4645
{ id: 'withBillingJwtV2.vue.vite', config: vue.vite, env: envs.withBillingJwtV2 },
47-
{ id: 'withBilling.vue.vite', config: vue.vite, env: envs.withBilling },
4846

4947
/**
5048
* Machine auth apps
@@ -68,7 +66,6 @@ export const createLongRunningApps = () => {
6866
/**
6967
* Various apps - basic flows
7068
*/
71-
{ id: 'withBilling.astro.node', config: astro.node, env: envs.withBilling },
7269
{ id: 'astro.node.withCustomRoles', config: astro.node, env: envs.withCustomRoles },
7370
{ id: 'astro.static.withCustomRoles', config: astro.static, env: envs.withCustomRoles },
7471
{ id: 'expo.expo-web', config: expo.expoWeb, env: envs.withEmailCodes },

integration/testUtils/usersService.ts

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import { faker } from '@faker-js/faker';
33

44
import { hash } from '../models/helpers';
55

6+
async function withErrorLogging<T>(operation: string, fn: () => Promise<T>): Promise<T> {
7+
try {
8+
return await fn();
9+
} catch (e: any) {
10+
console.error(`[usersService] ${operation} failed:`);
11+
console.error(' Status:', e.status);
12+
console.error(' Message:', e.message);
13+
console.error(' Errors:', JSON.stringify(e.errors, null, 2));
14+
console.error(' Clerk Trace ID:', e.clerkTraceId);
15+
throw e;
16+
}
17+
}
18+
619
type FakeUserOptions = {
720
/**
821
* A fictional email is an email that contains +clerk_test and can always be verified using 424242 as the OTP. No email will be sent.
@@ -126,15 +139,17 @@ export const createUserService = (clerkClient: ClerkClient) => {
126139
};
127140
},
128141
createBapiUser: async fakeUser => {
129-
return await clerkClient.users.createUser({
130-
emailAddress: fakeUser.email !== undefined ? [fakeUser.email] : undefined,
131-
password: fakeUser.password,
132-
firstName: fakeUser.firstName,
133-
lastName: fakeUser.lastName,
134-
phoneNumber: fakeUser.phoneNumber !== undefined ? [fakeUser.phoneNumber] : undefined,
135-
username: fakeUser.username,
136-
skipPasswordRequirement: fakeUser.password === undefined,
137-
});
142+
return withErrorLogging('createBapiUser', () =>
143+
clerkClient.users.createUser({
144+
emailAddress: fakeUser.email !== undefined ? [fakeUser.email] : undefined,
145+
password: fakeUser.password,
146+
firstName: fakeUser.firstName,
147+
lastName: fakeUser.lastName,
148+
phoneNumber: fakeUser.phoneNumber !== undefined ? [fakeUser.phoneNumber] : undefined,
149+
username: fakeUser.username,
150+
skipPasswordRequirement: fakeUser.password === undefined,
151+
}),
152+
);
138153
},
139154
getOrCreateUser: async fakeUser => {
140155
const existingUser = await self.getUser({ email: fakeUser.email });
@@ -147,10 +162,12 @@ export const createUserService = (clerkClient: ClerkClient) => {
147162
let id = opts.id;
148163

149164
if (!id) {
150-
const { data: users } = await clerkClient.users.getUserList({
151-
emailAddress: [opts.email],
152-
phoneNumber: [opts.phoneNumber],
153-
});
165+
const { data: users } = await withErrorLogging('getUserList', () =>
166+
clerkClient.users.getUserList({
167+
emailAddress: [opts.email],
168+
phoneNumber: [opts.phoneNumber],
169+
}),
170+
);
154171
id = users[0]?.id;
155172
}
156173

@@ -159,12 +176,12 @@ export const createUserService = (clerkClient: ClerkClient) => {
159176
return;
160177
}
161178

162-
await clerkClient.users.deleteUser(id);
179+
await withErrorLogging('deleteUser', () => clerkClient.users.deleteUser(id));
163180
},
164181
getUser: async (opts: { id?: string; email?: string }) => {
165182
if (opts.id) {
166183
try {
167-
const user = await clerkClient.users.getUser(opts.id);
184+
const user = await withErrorLogging('getUser', () => clerkClient.users.getUser(opts.id));
168185
return user;
169186
} catch (err) {
170187
console.log(`Error fetching user "${opts.id}": ${err.message}`);
@@ -173,7 +190,9 @@ export const createUserService = (clerkClient: ClerkClient) => {
173190
}
174191

175192
if (opts.email) {
176-
const { data: users } = await clerkClient.users.getUserList({ emailAddress: [opts.email] });
193+
const { data: users } = await withErrorLogging('getUserList', () =>
194+
clerkClient.users.getUserList({ emailAddress: [opts.email] }),
195+
);
177196
if (users.length > 0) {
178197
return users[0];
179198
} else {
@@ -186,33 +205,41 @@ export const createUserService = (clerkClient: ClerkClient) => {
186205
},
187206
createFakeOrganization: async userId => {
188207
const name = faker.animal.dog();
189-
const organization = await clerkClient.organizations.createOrganization({
190-
name: faker.animal.dog(),
191-
createdBy: userId,
192-
});
208+
const organization = await withErrorLogging('createOrganization', () =>
209+
clerkClient.organizations.createOrganization({
210+
name: faker.animal.dog(),
211+
createdBy: userId,
212+
}),
213+
);
193214
return {
194215
name,
195216
organization,
196-
delete: () => clerkClient.organizations.deleteOrganization(organization.id),
217+
delete: () =>
218+
withErrorLogging('deleteOrganization', () => clerkClient.organizations.deleteOrganization(organization.id)),
197219
} satisfies FakeOrganization;
198220
},
199221
createFakeAPIKey: async (userId: string) => {
200222
const TWENTY_MINUTES = 20 * 60;
201223

202-
const apiKey = await clerkClient.apiKeys.create({
203-
subject: userId,
204-
name: `Integration Test - ${faker.string.uuid()}`,
205-
secondsUntilExpiration: TWENTY_MINUTES,
206-
});
224+
const apiKey = await withErrorLogging('createAPIKey', () =>
225+
clerkClient.apiKeys.create({
226+
subject: userId,
227+
name: `Integration Test - ${faker.string.uuid()}`,
228+
secondsUntilExpiration: TWENTY_MINUTES,
229+
}),
230+
);
207231

208232
return {
209233
apiKey,
210234
secret: apiKey.secret ?? '',
211-
revoke: () => clerkClient.apiKeys.revoke({ apiKeyId: apiKey.id, revocationReason: 'For testing purposes' }),
235+
revoke: () =>
236+
withErrorLogging('revokeAPIKey', () =>
237+
clerkClient.apiKeys.revoke({ apiKeyId: apiKey.id, revocationReason: 'For testing purposes' }),
238+
),
212239
} satisfies FakeAPIKey;
213240
},
214241
passwordCompromised: async (userId: string) => {
215-
await clerkClient.users.__experimental_passwordCompromised(userId);
242+
await withErrorLogging('passwordCompromised', () => clerkClient.users.__experimental_passwordCompromised(userId));
216243
},
217244
};
218245

integration/tests/billing-hooks.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { expect, test } from '@playwright/test';
22

3-
import { appConfigs } from '../presets';
43
import type { FakeUser } from '../testUtils';
54
import { createTestUtils, testAgainstRunningApps } from '../testUtils';
65

7-
testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('billing hooks @billing', ({ app }) => {
6+
testAgainstRunningApps({})('billing hooks @billing', ({ app }) => {
87
test.describe.configure({ mode: 'parallel' });
98
test.skip(!app.name.includes('next'), 'Skipping: Only runs on next');
109

integration/tests/pricing-table.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type { Locator } from '@playwright/test';
22
import { expect, test } from '@playwright/test';
33

4-
import { appConfigs } from '../presets';
54
import type { FakeUser } from '../testUtils';
65
import { createTestUtils, testAgainstRunningApps } from '../testUtils';
76

8-
testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('pricing table @billing', ({ app }) => {
7+
testAgainstRunningApps({})('pricing table @billing', ({ app }) => {
98
test.describe.configure({ mode: 'parallel' });
109

1110
let fakeUser: FakeUser;
@@ -219,7 +218,7 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('pricing tabl
219218
});
220219
});
221220

222-
test('user is prompted to add email before checkout', async ({ page, context }) => {
221+
test.only('user is prompted to add email before checkout', async ({ page, context }) => {
223222
const u = createTestUtils({ app, page, context });
224223

225224
const fakeUser = u.services.users.createFakeUser({ withEmail: false, withPhoneNumber: true });

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"test:integration:ap-flows": "pnpm test:integration:base --grep @ap-flows",
3535
"test:integration:astro": "E2E_APP_ID=astro.* pnpm test:integration:base --grep @astro",
3636
"test:integration:base": "pnpm playwright test --config integration/playwright.config.ts",
37-
"test:integration:billing": "E2E_APP_ID=withBilling.* pnpm test:integration:base --grep @billing",
37+
"test:integration:billing": "E2E_DEBUG=1 E2E_APP_ID=withBillingJwtV2.* pnpm test:integration:base --grep @billing",
3838
"test:integration:cleanup": "pnpm playwright test --config integration/playwright.cleanup.config.ts",
3939
"test:integration:custom": "pnpm test:integration:base --grep @custom",
4040
"test:integration:deployment:nextjs": "pnpm playwright test --config integration/playwright.deployments.config.ts",

packages/shared/src/loadScript.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ export async function loadScript(src = '', opts: LoadScriptOptions): Promise<HTM
3636
script.defer = defer || false;
3737

3838
script.addEventListener('load', () => {
39-
console.log('this loaded ', src);
40-
4139
script.remove();
4240
resolve(script);
4341
});

packages/ui/rspack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const common = ({ mode, variant }) => {
4444
PACKAGE_VERSION: JSON.stringify(packageJSON.version),
4545
__PKG_VERSION__: JSON.stringify(packageJSON.version),
4646
PACKAGE_NAME: JSON.stringify(packageJSON.name),
47+
__BUILD_DISABLE_RHC__: JSON.stringify(false),
4748
}),
4849
new rspack.EnvironmentPlugin({
4950
NODE_ENV: mode,

packages/ui/tsdown.config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default defineConfig(({ watch }) => {
2020
PACKAGE_VERSION: `"${uiPackage.version}"`,
2121
__PKG_VERSION__: `"${uiPackage.version}"`,
2222
__DEV__: `${watch}`,
23+
__BUILD_DISABLE_RHC__: JSON.stringify(false),
2324
},
2425
} satisfies Options;
2526

0 commit comments

Comments
 (0)