Skip to content

Commit 1e3d107

Browse files
committed
update test config
1 parent ba60af1 commit 1e3d107

File tree

14 files changed

+137
-95
lines changed

14 files changed

+137
-95
lines changed

example/convex/_generated/api.d.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,33 @@ import type {
1616
FunctionReference,
1717
} from "convex/server";
1818

19+
declare const fullApi: ApiFromModules<{
20+
example: typeof example;
21+
}>;
22+
1923
/**
20-
* A utility for referencing Convex functions in your app's API.
24+
* A utility for referencing Convex functions in your app's public API.
2125
*
2226
* Usage:
2327
* ```js
2428
* const myFunctionReference = api.myModule.myFunction;
2529
* ```
2630
*/
27-
declare const fullApi: ApiFromModules<{
28-
example: typeof example;
29-
}>;
30-
declare const fullApiWithMounts: typeof fullApi;
31-
3231
export declare const api: FilterApi<
33-
typeof fullApiWithMounts,
32+
typeof fullApi,
3433
FunctionReference<any, "public">
3534
>;
35+
36+
/**
37+
* A utility for referencing Convex functions in your app's internal API.
38+
*
39+
* Usage:
40+
* ```js
41+
* const myFunctionReference = internal.myModule.myFunction;
42+
* ```
43+
*/
3644
export declare const internal: FilterApi<
37-
typeof fullApiWithMounts,
45+
typeof fullApi,
3846
FunctionReference<any, "internal">
3947
>;
4048

@@ -45,7 +53,7 @@ export declare const components: {
4553
"mutation",
4654
"internal",
4755
{ logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR"; userId: string },
48-
any
56+
null
4957
>;
5058
getNotification: FunctionReference<
5159
"query",

example/convex/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default defineSchema({
55
users: defineTable(
66
v.object({
77
name: v.string(),
8-
})
8+
}),
99
).index("by_name", ["name"]),
1010
// Any tables used by the example app go here.
1111
});

example/convex/setup.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference types="vite/client" />
2+
import { test } from "vitest";
3+
import { convexTest } from "convex-test";
4+
import schema from "./schema.js";
5+
import component from "@convex-dev/expo-push-notifications/test";
6+
7+
const modules = import.meta.glob("./**/*.*s");
8+
// When users want to write tests that use your component, they need to
9+
// explicitly register it with its schema and modules.
10+
export function initConvexTest() {
11+
const t = convexTest(schema, modules);
12+
component.register(t);
13+
return t;
14+
}
15+
16+
test("setup", () => {});

example/convex/tsconfig.json

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
{
2-
"compilerOptions": {
3-
"allowJs": true,
4-
"strict": true,
5-
"skipLibCheck": true,
6-
"target": "ESNext",
7-
"lib": ["ES2021", "dom", "DOM.Iterable", "ESNext.Array"],
8-
"forceConsistentCasingInFileNames": true,
9-
"allowSyntheticDefaultImports": true,
10-
"verbatimModuleSyntax": true,
11-
"module": "ESNext",
12-
"moduleResolution": "Bundler",
13-
"isolatedModules": true,
14-
"noEmit": true,
15-
"jsx": "react-jsx"
16-
},
17-
"include": [".*"],
18-
"exclude": ["./_generated"]
2+
"extends": "../tsconfig.json",
3+
"include": ["."],
4+
"exclude": ["_generated"]
195
}

example/vite.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import react from "@vitejs/plugin-react";
33

44
// https://vitejs.dev/config/
55
export default defineConfig({
6+
envDir: "../",
67
plugins: [react()],
7-
resolve: {
8-
conditions: ["@convex-dev/component-source"],
9-
},
108
});

src/client/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class PushNotifications<UserType extends string = GenericId<"users">> {
2828
public component: ComponentApi,
2929
config?: {
3030
logLevel?: LogLevel;
31-
}
31+
},
3232
) {
3333
this.component = component;
3434
this.config = {
@@ -44,7 +44,7 @@ export class PushNotifications<UserType extends string = GenericId<"users">> {
4444
*/
4545
recordToken(
4646
ctx: RunMutationCtx,
47-
args: { userId: UserType; pushToken: string }
47+
args: { userId: UserType; pushToken: string },
4848
): Promise<null> {
4949
return ctx.runMutation(this.component.public.recordPushNotificationToken, {
5050
...args,
@@ -94,7 +94,7 @@ export class PushNotifications<UserType extends string = GenericId<"users">> {
9494
userId: UserType;
9595
notification: NotificationFields;
9696
allowUnregisteredTokens?: boolean;
97-
}
97+
},
9898
) {
9999
return ctx.runMutation(this.component.public.sendPushNotification, {
100100
...args,
@@ -117,7 +117,7 @@ export class PushNotifications<UserType extends string = GenericId<"users">> {
117117
notification: NotificationFields;
118118
}>;
119119
allowUnregisteredTokens?: boolean;
120-
}
120+
},
121121
) {
122122
return ctx.runMutation(this.component.public.sendPushNotificationBatch, {
123123
...args,
@@ -141,7 +141,7 @@ export class PushNotifications<UserType extends string = GenericId<"users">> {
141141
*/
142142
getNotificationsForUser(
143143
ctx: RunQueryCtx,
144-
args: { userId: UserType; limit?: number }
144+
args: { userId: UserType; limit?: number },
145145
) {
146146
return ctx.runQuery(this.component.public.getNotificationsForUser, {
147147
...args,

src/component/helpers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ export async function ensureCoordinator(ctx: MutationCtx) {
1919
}
2020
if (activeCoordinators.length === 1) {
2121
ctx.logger.debug(
22-
`Found existing coordinator with ID ${activeCoordinators[0]._id}`
22+
`Found existing coordinator with ID ${activeCoordinators[0]._id}`,
2323
);
2424
return;
2525
}
2626
if (activeCoordinators.length > 1) {
2727
ctx.logger.error(
28-
`Unexpected state: Too many coordinators ${activeCoordinators.length}`
28+
`Unexpected state: Too many coordinators ${activeCoordinators.length}`,
2929
);
3030
throw new Error(
31-
`Unexpected state: Too many coordinators ${activeCoordinators.length}`
31+
`Unexpected state: Too many coordinators ${activeCoordinators.length}`,
3232
);
3333
}
3434
const config = await ctx.db.query("config").unique();
@@ -41,7 +41,7 @@ export async function ensureCoordinator(ctx: MutationCtx) {
4141
internal.internal.coordinateSendingPushNotifications,
4242
{
4343
logLevel: ctx.logger.level,
44-
}
44+
},
4545
);
4646
const coordinatorId = await ctx.db.insert("senderCoordinator", {
4747
jobId: coordinatorJobId,
@@ -88,7 +88,7 @@ export const shutdownGracefully = async (ctx: MutationCtx) => {
8888
const _typeCheck: never = job.state;
8989
ctx.logger.error(
9090
// eslint-disable-next-line @typescript-eslint/no-explicit-any
91-
`Unknown job state ${(job.state as any).kind} for sender ${sender._id}. Cleaning it up. `
91+
`Unknown job state ${(job.state as any).kind} for sender ${sender._id}. Cleaning it up. `,
9292
);
9393
await ctx.db.delete(sender._id);
9494
break;

src/component/internal.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export const markNotificationState = internalMutation({
1313
state: v.union(
1414
v.literal("delivered"),
1515
v.literal("failed"),
16-
v.literal("maybe_delivered")
16+
v.literal("maybe_delivered"),
1717
),
18-
})
18+
}),
1919
),
2020
checkJobId: v.id("_scheduled_functions"),
2121
},
@@ -71,7 +71,7 @@ export const coordinateSendingPushNotifications = internalMutation({
7171
.withIndex("state", (q) => q.eq("state", "awaiting_delivery"))
7272
.take(MAX_NOTIFICATIONS_PER_SEND - retryNotifications.length);
7373
ctx.logger.debug(
74-
`Found ${retryNotifications.length} retry notifications and ${unsentNotifications.length} unsent notifications`
74+
`Found ${retryNotifications.length} retry notifications and ${unsentNotifications.length} unsent notifications`,
7575
);
7676
const notificationsToProcess = [
7777
...retryNotifications,
@@ -101,18 +101,18 @@ export const coordinateSendingPushNotifications = internalMutation({
101101
if (numActiveSenders >= MAX_SENDERS) {
102102
// Don't add another sender yet
103103
ctx.logger.debug(
104-
`Not starting another sender: already ${numActiveSenders}`
104+
`Not starting another sender: already ${numActiveSenders}`,
105105
);
106106
ctx.logger.debug(
107-
`When one sender finishes, or fails, we'll coordinate sending these notifications.`
107+
`When one sender finishes, or fails, we'll coordinate sending these notifications.`,
108108
);
109109
return;
110110
}
111111
const notificationsToSend = notificationsToProcess.filter(
112-
(n) => n.numPreviousFailures < MAX_RETRY_ATTEMPTS
112+
(n) => n.numPreviousFailures < MAX_RETRY_ATTEMPTS,
113113
);
114114
const notificationsToMarkAsUnableToDeliver = notificationsToProcess.filter(
115-
(n) => n.numPreviousFailures >= MAX_RETRY_ATTEMPTS
115+
(n) => n.numPreviousFailures >= MAX_RETRY_ATTEMPTS,
116116
);
117117

118118
for (const notification of notificationsToMarkAsUnableToDeliver) {
@@ -134,7 +134,7 @@ export const coordinateSendingPushNotifications = internalMutation({
134134
{
135135
notificationIds: notificationsToSend.map((n) => n._id),
136136
logLevel: ctx.logger.level,
137-
}
137+
},
138138
);
139139

140140
const senderJobId = await ctx.scheduler.runAfter(
@@ -165,14 +165,14 @@ export const coordinateSendingPushNotifications = internalMutation({
165165
};
166166
}),
167167
logLevel: ctx.logger.level,
168-
}
168+
},
169169
);
170170
await ctx.db.insert("senders", {
171171
jobId: senderJobId,
172172
checkJobId,
173173
});
174174
ctx.logger.debug(
175-
`Started a new sender ${senderJobId} with job ${senderJobId} and check job ${checkJobId}`
175+
`Started a new sender ${senderJobId} with job ${senderJobId} and check job ${checkJobId}`,
176176
);
177177
},
178178
});
@@ -184,7 +184,7 @@ export const checkForFailedAction = internalMutation({
184184
handler: async (ctx, { notificationIds }) => {
185185
console.warn(
186186
`Could not determine delivery status for ${notificationIds.length} notifications:`,
187-
notificationIds
187+
notificationIds,
188188
);
189189
for (const notificationId of notificationIds) {
190190
// We don't really know what happened to these notifications,
@@ -204,18 +204,18 @@ export const action_sendPushNotifications = internalAction({
204204
v.object({
205205
message: v.object({
206206
to: v.string(),
207-
...notificationFields
207+
...notificationFields,
208208
}),
209209
_id: v.id("notifications"),
210-
})
210+
}),
211211
),
212212
},
213213
handler: async (ctx, args) => {
214214
ctx.logger.debug(
215-
`Sending ${args.notifications.length} push notifications via Expo's API`
215+
`Sending ${args.notifications.length} push notifications via Expo's API`,
216216
);
217217
ctx.logger.debug(
218-
`Notification IDs: ${JSON.stringify(args.notifications.map((n) => n._id))}`
218+
`Notification IDs: ${JSON.stringify(args.notifications.map((n) => n._id))}`,
219219
);
220220
let response: Response;
221221
try {
@@ -232,10 +232,10 @@ export const action_sendPushNotifications = internalAction({
232232
} catch (_e) {
233233
ctx.logger.error(
234234
"Failed during during fetch for sending push notifications:",
235-
_e
235+
_e,
236236
);
237237
ctx.logger.debug(
238-
`Marking ${args.notifications.length} notifications as failed so they can be retried`
238+
`Marking ${args.notifications.length} notifications as failed so they can be retried`,
239239
);
240240
await ctx.runMutation(internal.internal.markNotificationState, {
241241
notifications: args.notifications.map((n) => {
@@ -253,10 +253,10 @@ export const action_sendPushNotifications = internalAction({
253253
}
254254
if (!response.ok) {
255255
ctx.logger.warn(
256-
`Push notification failed with status ${response.status} and body ${await response.text()}`
256+
`Push notification failed with status ${response.status} and body ${await response.text()}`,
257257
);
258258
ctx.logger.debug(
259-
`Marking ${args.notifications.length} notifications as maybe delivered. They won't be retried.`
259+
`Marking ${args.notifications.length} notifications as maybe delivered. They won't be retried.`,
260260
);
261261
await ctx.runMutation(internal.internal.markNotificationState, {
262262
notifications: args.notifications.map((n) => {
@@ -279,7 +279,7 @@ export const action_sendPushNotifications = internalAction({
279279
>;
280280
} = await response.json();
281281
ctx.logger.debug(
282-
`Response from Expo's API: ${JSON.stringify(responseBody)}`
282+
`Response from Expo's API: ${JSON.stringify(responseBody)}`,
283283
);
284284

285285
const notificationStates: Array<{
@@ -302,7 +302,7 @@ export const action_sendPushNotifications = internalAction({
302302
}
303303
}
304304
ctx.logger.debug(
305-
`Successfully parsed response from Expo, and recording state`
305+
`Successfully parsed response from Expo, and recording state`,
306306
);
307307
await ctx.runMutation(internal.internal.markNotificationState, {
308308
notifications: notificationStates,

0 commit comments

Comments
 (0)