Skip to content

Commit aa5bcc2

Browse files
committed
test: allow server github verifier without web source
1 parent aa3580d commit aa5bcc2

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

scripts/verify-github-account-linking.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,17 @@ if (oldClientSecret === undefined) delete process.env.AUTH_GITHUB_CLIENT_SECRET;
126126
else process.env.AUTH_GITHUB_CLIENT_SECRET = oldClientSecret;
127127

128128
const root = new URL("../", import.meta.url);
129+
const readOptional = async (path: string) => {
130+
try {
131+
return await readFile(new URL(path, root), "utf8");
132+
} catch (error) {
133+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return null;
134+
throw error;
135+
}
136+
};
129137
const auth = await readFile(new URL("apps/api/src/routes/auth.ts", root), "utf8");
130138
const db = await readFile(new URL("apps/api/src/lib/db.ts", root), "utf8");
131-
const setting = await readFile(new URL("apps/web/app/routes/setting.tsx", root), "utf8");
139+
const setting = await readOptional("apps/web/app/routes/setting.tsx");
132140
const migration = await readFile(
133141
new URL("packages/db/migrations/pg/0000_github_id_unique.sql", root),
134142
"utf8",
@@ -145,10 +153,12 @@ assert.doesNotMatch(
145153
/console\.(?:log|error)\([^\n]*(?:ghAccessToken|profile\.accessToken|password|clientSecret)/,
146154
);
147155
assert.match(db, /githubId: null, githubUsername: null, githubAccessToken: null/);
148-
assert.match(setting, /divide-y divide-border\/70/);
149-
assert.match(setting, / GitHub /);
150-
assert.match(setting, //);
151-
assert.match(setting, /isSubmitting \? "\.\.\."/);
156+
if (setting) {
157+
assert.match(setting, /divide-y divide-border\/70/);
158+
assert.match(setting, / GitHub /);
159+
assert.match(setting, //);
160+
assert.match(setting, /isSubmitting \? "\.\.\."/);
161+
}
152162
assert.match(migration, /HAVING COUNT\(\*\) > 1/);
153163
assert.match(migration, /CREATE UNIQUE INDEX IF NOT EXISTS "users_github_id_unique"/);
154164
assert.match(migration, /ON "users" \("github_id"\)/);

0 commit comments

Comments
 (0)