Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

feat(api)!: remove the Reddit account route

spacesdrivecaaccb67cbed
diff --git a/backend/controllers/accountController.ts b/backend/controllers/accountController.ts
index 01b03d9..2f996f2 100644
--- a/backend/controllers/accountController.ts
+++ b/backend/controllers/accountController.ts
@@ -1,6 +1,6 @@
import { controller, pathParam, servicesFor } from './http.ts';
import { jsonBody } from '../middleware/validate.ts';
-import { parseChannelInput, parseInstagramToken, parseRedditAccount } from '../validators/accountValidators.ts';
+import { parseChannelInput, parseInstagramToken } from '../validators/accountValidators.ts';
import { safeAccount } from '../lib/safeAccount.ts';
import type {
AccountListResponse, AccountRefreshAllResponse, AccountResponse, SuccessResponse, YouTubeAccountAddResponse,
@@ -25,11 +25,6 @@ export const addYouTubeAccount = controller.createHandlers(jsonBody(parseChannel
return c.json({ success: true, account } satisfies YouTubeAccountAddResponse);
});
-export const addRedditAccount = controller.createHandlers(jsonBody(parseRedditAccount), async c => {
- const account = await servicesFor(c).accounts.addReddit(c.get('userId'), c.req.valid('json'));
- return c.json({ success: true, account: safeAccount(account) } satisfies AccountResponse);
-});
-
export const addInstagramAccount = controller.createHandlers(jsonBody(parseInstagramToken), async c => {
const account = await servicesFor(c).accounts.addInstagram(c.get('userId'), c.req.valid('json').accessToken);
return c.json({ success: true, account: safeAccount(account) } satisfies AccountResponse);
diff --git a/backend/lib/rateLimit/rules.ts b/backend/lib/rateLimit/rules.ts
index cff3880..9c4cf28 100644
--- a/backend/lib/rateLimit/rules.ts
+++ b/backend/lib/rateLimit/rules.ts
@@ -17,7 +17,7 @@ export const RATE_LIMIT_RULES = {
label: 'Too many requests',
config: { algorithm: 'tokenBucket', capacity: 120, refillPerSecond: 2 },
},
- // these spend the shared YouTube quota and Instagram and Reddit API calls, so the count is exact
+ // these spend the shared YouTube quota and Instagram API calls, so the count is exact
quota: {
name: 'quota',
label: 'Too many account changes and refreshes',
@@ -45,7 +45,7 @@ interface RouteMatcher {
// paths are matched on the full request path, after the /api prefix
export const QUOTA_ROUTES: readonly RouteMatcher[] = [
{ methods: ['POST'], path: /^\/api\/accounts$/ },
- { methods: ['POST'], path: /^\/api\/accounts\/(reddit|instagram|refresh-all)$/ },
+ { methods: ['POST'], path: /^\/api\/accounts\/(instagram|refresh-all)$/ },
{ methods: ['POST'], path: /^\/api\/accounts\/[^/]+\/(refresh|refresh-ig-token)$/ },
{ methods: ['POST'], path: /^\/api\/resolve-channel$/ },
{ methods: ['POST'], path: /^\/api\/tracked-content$/ },
diff --git a/backend/routes/accountRoutes.ts b/backend/routes/accountRoutes.ts
index e7b0532..b5bc35b 100644
--- a/backend/routes/accountRoutes.ts
+++ b/backend/routes/accountRoutes.ts
@@ -1,6 +1,6 @@
import { Hono } from 'hono';
import {
- listAccounts, resolveChannel, addYouTubeAccount, addRedditAccount, addInstagramAccount,
+ listAccounts, resolveChannel, addYouTubeAccount, addInstagramAccount,
refreshAllAccounts, refreshAccount, refreshInstagramToken, deleteAccount,
} from '../controllers/accountController.ts';
import type { AppEnv } from '../types/app.ts';
@@ -10,7 +10,6 @@ const router = new Hono<AppEnv>();
router.get('/accounts', ...listAccounts);
router.post('/resolve-channel', ...resolveChannel);
router.post('/accounts', ...addYouTubeAccount);
-router.post('/accounts/reddit', ...addRedditAccount);
router.post('/accounts/instagram', ...addInstagramAccount);
router.post('/accounts/refresh-all', ...refreshAllAccounts);
router.post('/accounts/:id/refresh-ig-token', ...refreshInstagramToken);
diff --git a/backend/services/accountFactory.ts b/backend/services/accountFactory.ts
index 091b04f..6a11e9c 100644
--- a/backend/services/accountFactory.ts
+++ b/backend/services/accountFactory.ts
@@ -1,7 +1,6 @@
import { newRowId } from '../lib/ids.ts';
import type { Account, NewAccount } from '../../shared/types/domain.ts';
import type { YouTubeChannelData } from '../../shared/types/youtube.ts';
-import type { RedditProfile } from '../../shared/types/reddit.ts';
import type { InstagramProfile } from '../../shared/types/instagram.ts';
// a token without a known lifetime is stored with no expiry
@@ -34,23 +33,6 @@ export function buildYouTubeAccount(channelData: YouTubeChannelData): NewAccount
};
}
-export function buildRedditAccount(profile: RedditProfile, cookie: string): Account {
- return {
- id: newRowId(),
- platform: 'reddit',
- username: profile.username,
- title: `u/${profile.username}`,
- totalKarma: profile.totalKarma,
- postKarma: profile.postKarma,
- commentKarma: profile.commentKarma,
- iconUrl: profile.iconUrl,
- createdAt: profile.createdAt,
- cookie,
- addedAt: new Date().toISOString(),
- lastUpdated: new Date().toISOString(),
- };
-}
-
export function buildInstagramAccount(profile: InstagramProfile, accessToken: string, expiresIn: number): Account {
return {
id: newRowId(),
diff --git a/backend/services/accountService.ts b/backend/services/accountService.ts
index f70724d..9dff205 100644
--- a/backend/services/accountService.ts
+++ b/backend/services/accountService.ts
@@ -1,8 +1,7 @@
import { resolveChannelId, fetchChannelData } from './youtube/youtubeChannels.ts';
-import { fetchRedditProfile } from './reddit/redditApi.ts';
import { fetchInstagramProfile } from './instagram/instagramApi.ts';
import { exchangeForLongLivedToken, refreshLongLivedToken } from './instagram/instagramTokens.ts';
-import { buildYouTubeAccount, buildRedditAccount, buildInstagramAccount } from './accountFactory.ts';
+import { buildYouTubeAccount, buildInstagramAccount } from './accountFactory.ts';
import { ConflictError, NotConfiguredError, NotFoundError, ValidationError, isUniqueViolation } from '../lib/errors.ts';
import type { AccountRepository } from '../repositories/accountRepository.ts';
import type { AnalyticsCacheRepository } from '../repositories/analyticsCacheRepository.ts';
@@ -11,7 +10,6 @@ import type { AppConfig } from '../lib/config.ts';
import type { RequestContext } from '../types/context.ts';
import type { Account, AccountRefreshResult, NewAccount } from '../../shared/types/domain.ts';
import type { YouTubeChannelData } from '../../shared/types/youtube.ts';
-import type { RedditProfile } from '../../shared/types/reddit.ts';
import type { InstagramProfile } from '../../shared/types/instagram.ts';
export interface AccountServiceDeps {
@@ -22,11 +20,6 @@ export interface AccountServiceDeps {
context: RequestContext;
}
-export interface RedditAccountInput {
- username: string;
- cookie: string;
-}
-
export interface RefreshAllOutcome {
accounts: Account[];
results: AccountRefreshResult[];
@@ -36,7 +29,6 @@ export interface AccountService {
list(userId: string): Promise<Account[]>;
resolveChannel(input: string): Promise<YouTubeChannelData>;
addYouTube(userId: string, input: string): Promise<NewAccount>;
- addReddit(userId: string, input: RedditAccountInput): Promise<Account>;
addInstagram(userId: string, accessToken: string): Promise<Account>;
refresh(userId: string, accountId: string): Promise<Account>;
refreshAll(userId: string): Promise<RefreshAllOutcome>;
@@ -51,9 +43,7 @@ interface PastedToken {
const DEFAULT_TOKEN_LIFETIME_S = 5184000;
export const NO_YOUTUBE_KEY_MESSAGE = 'YouTube API key not configured on server';
-export const NO_COOKIE_MESSAGE = 'No session cookie stored - re-add this account with a session cookie from reddit.com DevTools';
const NO_TOKEN_MESSAGE = 'No access token stored - reconnect this Instagram account';
-const NO_USERNAME_MESSAGE = 'No Reddit username stored - delete this account and add it again';
const NO_CHANNEL_MESSAGE = 'No YouTube channel ID stored - delete this channel and add it again';
// full adds the fields only a single account refresh updates
@@ -70,15 +60,6 @@ function instagramUpdates(profile: InstagramProfile, full: boolean): Partial<Acc
return { ...updates, biography: profile.biography, website: profile.website };
}
-function redditUpdates(profile: RedditProfile): Partial<Account> {
- return {
- totalKarma: profile.totalKarma,
- postKarma: profile.postKarma,
- commentKarma: profile.commentKarma,
- iconUrl: profile.iconUrl,
- };
-}
-
function youtubeUpdates(channelData: YouTubeChannelData, full: boolean): Partial<Account> {
const { subscriberCount, viewCount, videoCount, title, thumbnails } = channelData;
if (!full) return { subscriberCount, viewCount, videoCount, title, thumbnails };
@@ -94,7 +75,6 @@ function youtubeUpdates(channelData: YouTubeChannelData, full: boolean): Partial
}
const CHANNEL_ADDED = 'This channel is already added';
-const REDDIT_ADDED = 'This Reddit account is already added';
const INSTAGRAM_ADDED = 'This Instagram account is already added';
export function createAccountService({ accounts, cache, audit, config, context }: AccountServiceDeps): AccountService {
@@ -140,11 +120,6 @@ export function createAccountService({ accounts, cache, audit, config, context }
if (!account.accessToken) throw new ValidationError(NO_TOKEN_MESSAGE);
return instagramUpdates(await fetchInstagramProfile(account.igUserId, account.accessToken, signal), full);
}
- if (account.platform === 'reddit') {
- if (!account.username) throw new ValidationError(NO_USERNAME_MESSAGE);
- if (!account.cookie) throw new ValidationError(NO_COOKIE_MESSAGE);
- return redditUpdates(await fetchRedditProfile(account.username, account.cookie, signal));
- }
if (!account.channelId) throw new ValidationError(NO_CHANNEL_MESSAGE);
return youtubeUpdates(await fetchChannelData(account.channelId, youtubeKey(), signal), full);
}
@@ -176,18 +151,6 @@ export function createAccountService({ accounts, cache, audit, config, context }
return account;
},
- async addReddit(userId, { username, cookie }) {
- const profile = await fetchRedditProfile(username.replace(/^u\//i, '').trim(), cookie, signal);
- const existing = await accounts.listForUser(userId);
- if (existing.find(account => account.platform === 'reddit' && account.username === profile.username)) {
- throw new ConflictError(REDDIT_ADDED);
- }
-
- const account = buildRedditAccount(profile, cookie);
- await createUnlessAdded(account, userId, REDDIT_ADDED);
- return account;
- },
-
async addInstagram(userId, accessToken) {
const { token, expiresIn } = await exchangePastedToken(accessToken);
const profile = await fetchInstagramProfile(null, token, signal);
diff --git a/backend/tests/fixtures/accountsRoutes.addReddit.golden.json b/backend/tests/fixtures/accountsRoutes.addReddit.golden.json
deleted file mode 100644
index ecf58d6..0000000
--- a/backend/tests/fixtures/accountsRoutes.addReddit.golden.json
+++ /dev/null
@@ -1,101 +0,0 @@
-{
- "responses": [
- {
- "status": 400,
- "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"Enter the Reddit username, such as u/name\",\"requestId\":\"req-test\"}"
- },
- {
- "status": 400,
- "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"Session cookie is required - open reddit.com in your browser, copy the reddit_session value from DevTools (Application > Cookies > reddit.com), and paste it here\",\"requestId\":\"req-test\"}"
- },
- {
- "status": 200,
- "body": "{\"success\":true,\"account\":{\"id\":\"00000000-0000-4000-8000-000000000001\",\"platform\":\"reddit\",\"username\":\"NewUser\",\"title\":\"u/NewUser\",\"totalKarma\":70,\"postKarma\":50,\"commentKarma\":20,\"iconUrl\":\"https://i?a=1&b=2\",\"createdAt\":\"2020-09-13T12:26:40.000Z\",\"addedAt\":\"2026-09-01T12:00:00.000Z\",\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"hasCookie\":true}}"
- },
- {
- "status": 409,
- "body": "{\"success\":false,\"code\":\"CONFLICT\",\"message\":\"This Reddit account is already added\",\"requestId\":\"req-test\"}"
- },
- {
- "status": 404,
- "body": "{\"success\":false,\"code\":\"NOT_FOUND\",\"message\":\"Reddit user not found - check the username\",\"requestId\":\"req-test\"}"
- }
- ],
- "requests": [
- {
- "url": "https://www.reddit.com/user/NewUser/about.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json",
- "Cookie": "reddit_session=NEWCOOKIE"
- }
- },
- {
- "url": "https://www.reddit.com/user/ribbon_r/about.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json",
- "Cookie": "reddit_session=C2"
- }
- },
- {
- "url": "https://www.reddit.com/user/missing/about.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json",
- "Cookie": "reddit_session=C3"
- }
- }
- ],
- "calls": [
- {
- "type": "select",
- "table": "accounts",
- "columns": "id, platform, data",
- "filters": [
- [
- "user_id",
- "user-1"
- ]
- ]
- },
- {
- "type": "insert",
- "table": "accounts",
- "values": {
- "id": "00000000-0000-4000-8000-000000000001",
- "user_id": "user-1",
- "platform": "reddit",
- "data": {
- "username": "NewUser",
- "title": "u/NewUser",
- "totalKarma": 70,
- "postKarma": 50,
- "commentKarma": 20,
- "iconUrl": "https://i?a=1&b=2",
- "createdAt": "2020-09-13T12:26:40.000Z",
- "cookie": "NEWCOOKIE",
- "addedAt": "2026-09-01T12:00:00.000Z",
- "lastUpdated": "2026-09-01T12:00:00.000Z"
- }
- },
- "filters": []
- },
- {
- "type": "select",
- "table": "accounts",
- "columns": "id, platform, data",
- "filters": [
- [
- "user_id",
- "user-1"
- ]
- ]
- }
- ],
- "redis": [],
- "logs": []
-}
diff --git a/backend/tests/fixtures/accountsRoutes.dbFailure.golden.json b/backend/tests/fixtures/accountsRoutes.dbFailure.golden.json
index 659602c..ee1ef25 100644
--- a/backend/tests/fixtures/accountsRoutes.dbFailure.golden.json
+++ b/backend/tests/fixtures/accountsRoutes.dbFailure.golden.json
@@ -24,10 +24,6 @@
"status": 500,
"body": "{\"success\":false,\"code\":\"DATABASE_ERROR\",\"message\":\"The database request failed. Try again in a moment.\",\"requestId\":\"req-test\"}"
},
- {
- "status": 500,
- "body": "{\"success\":false,\"code\":\"DATABASE_ERROR\",\"message\":\"The database request failed. Try again in a moment.\",\"requestId\":\"req-test\"}"
- },
{
"status": 500,
"body": "{\"success\":false,\"code\":\"DATABASE_ERROR\",\"message\":\"The database request failed. Try again in a moment.\",\"requestId\":\"req-test\"}"
@@ -42,15 +38,6 @@
"url": "https://www.googleapis.com/youtube/v3/channels?part=snippet%2Cstatistics%2CcontentDetails%2CbrandingSettings%2Cstatus%2CtopicDetails&id=UCnnnnnnnnnnnnnnnnnnnnnn&key=YTKEY",
"method": "GET"
},
- {
- "url": "https://www.reddit.com/user/NewUser/about.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json",
- "Cookie": "reddit_session=C"
- }
- },
{
"url": "https://graph.instagram.com/v25.0/me?access_token=IGTOKEN&fields=user_id%2Cusername%2Cname%2Cprofile_picture_url%2Cfollowers_count%2Cfollows_count%2Cmedia_count%2Cbiography%2Cwebsite",
"method": "GET"
@@ -83,10 +70,6 @@
"error",
"{\"level\":\"error\",\"message\":\"request failed\",\"requestId\":\"req-test\",\"userId\":\"user-1\",\"code\":\"DATABASE_ERROR\",\"status\":500,\"error\":\"The database request failed. Try again in a moment.\",\"errorName\":\"DatabaseError\",\"cause\":\"database unavailable\"}"
],
- [
- "error",
- "{\"level\":\"error\",\"message\":\"request failed\",\"requestId\":\"req-test\",\"userId\":\"user-1\",\"code\":\"DATABASE_ERROR\",\"status\":500,\"error\":\"The database request failed. Try again in a moment.\",\"errorName\":\"DatabaseError\",\"cause\":\"database unavailable\"}"
- ],
[
"error",
"{\"level\":\"error\",\"message\":\"request failed\",\"requestId\":\"req-test\",\"userId\":\"user-1\",\"code\":\"DATABASE_ERROR\",\"status\":500,\"error\":\"The database request failed. Try again in a moment.\",\"errorName\":\"DatabaseError\",\"cause\":\"database unavailable\"}"
diff --git a/backend/tests/fixtures/accountsRoutes.delete.golden.json b/backend/tests/fixtures/accountsRoutes.delete.golden.json
index 04727ee..d316a3c 100644
--- a/backend/tests/fixtures/accountsRoutes.delete.golden.json
+++ b/backend/tests/fixtures/accountsRoutes.delete.golden.json
@@ -14,7 +14,11 @@
},
{
"status": 200,
- "body": "[{\"id\":\"yt1\",\"platform\":\"youtube\",\"channelId\":\"UCaaaaaaaaaaaaaaaaaaaaaa\",\"title\":\"Old title\",\"subscriberCount\":1,\"hasCookie\":false},{\"id\":\"ig1\",\"platform\":\"instagram\",\"igUserId\":\"1789\",\"username\":\"ribbon\",\"tokenExpiresAt\":\"2026-09-05T00:00:00.000Z\",\"followersCount\":1,\"hasCookie\":false},{\"id\":\"ig2\",\"platform\":\"instagram\",\"igUserId\":\"2000\",\"username\":\"notoken\",\"hasCookie\":false},{\"id\":\"rd1\",\"platform\":\"reddit\",\"username\":\"ribbon_r\",\"totalKarma\":1,\"hasCookie\":true},{\"id\":\"yt2\",\"platform\":\"youtube\",\"channelId\":\"UCmissingmissingmissing0\",\"hasCookie\":false}]"
+ "body": "{\"success\":true}"
+ },
+ {
+ "status": 200,
+ "body": "[{\"id\":\"yt1\",\"platform\":\"youtube\",\"channelId\":\"UCaaaaaaaaaaaaaaaaaaaaaa\",\"title\":\"Old title\",\"subscriberCount\":1,\"hasCookie\":false},{\"id\":\"ig1\",\"platform\":\"instagram\",\"igUserId\":\"1789\",\"username\":\"ribbon\",\"tokenExpiresAt\":\"2026-09-05T00:00:00.000Z\",\"followersCount\":1,\"hasCookie\":false},{\"id\":\"ig2\",\"platform\":\"instagram\",\"igUserId\":\"2000\",\"username\":\"notoken\",\"hasCookie\":false}]"
}
],
"requests": [],
@@ -56,7 +60,7 @@
"filters": [
[
"id",
- "rd2"
+ "old1"
],
[
"user_id",
@@ -70,7 +74,7 @@
"filters": [
[
"id",
- "rd2"
+ "old1"
],
[
"user_id",
@@ -86,9 +90,53 @@
"user_id": "user-1",
"action": "account.removed",
"subject_type": "account",
- "subject_id": "rd2",
+ "subject_id": "old1",
+ "details": {
+ "platform": "retired"
+ }
+ },
+ "filters": []
+ },
+ {
+ "type": "select",
+ "table": "accounts",
+ "columns": "id, platform, data",
+ "filters": [
+ [
+ "id",
+ "yt2"
+ ],
+ [
+ "user_id",
+ "user-1"
+ ]
+ ]
+ },
+ {
+ "type": "delete",
+ "table": "accounts",
+ "filters": [
+ [
+ "id",
+ "yt2"
+ ],
+ [
+ "user_id",
+ "user-1"
+ ]
+ ]
+ },
+ {
+ "type": "insert",
+ "table": "audit_events",
+ "values": {
+ "id": "00000000-0000-4000-8000-000000000002",
+ "user_id": "user-1",
+ "action": "account.removed",
+ "subject_type": "account",
+ "subject_id": "yt2",
"details": {
- "platform": "reddit"
+ "platform": "youtube"
}
},
"filters": []
@@ -106,9 +154,12 @@
}
],
"redis": [
- "videos:user-1:rd2",
- "ig:user-1:rd2",
- "reddit:user-1:rd2"
+ "videos:user-1:old1",
+ "ig:user-1:old1",
+ "reddit:user-1:old1",
+ "videos:user-1:yt2",
+ "ig:user-1:yt2",
+ "reddit:user-1:yt2"
],
"logs": []
}
diff --git a/backend/tests/fixtures/accountsRoutes.listResolve.golden.json b/backend/tests/fixtures/accountsRoutes.listResolve.golden.json
index 1981451..f4df467 100644
--- a/backend/tests/fixtures/accountsRoutes.listResolve.golden.json
+++ b/backend/tests/fixtures/accountsRoutes.listResolve.golden.json
@@ -2,7 +2,7 @@
"responses": [
{
"status": 200,
- "body": "[{\"id\":\"yt1\",\"platform\":\"youtube\",\"channelId\":\"UCaaaaaaaaaaaaaaaaaaaaaa\",\"title\":\"Old title\",\"subscriberCount\":1,\"hasCookie\":false},{\"id\":\"ig1\",\"platform\":\"instagram\",\"igUserId\":\"1789\",\"username\":\"ribbon\",\"tokenExpiresAt\":\"2026-09-05T00:00:00.000Z\",\"followersCount\":1,\"hasCookie\":false},{\"id\":\"ig2\",\"platform\":\"instagram\",\"igUserId\":\"2000\",\"username\":\"notoken\",\"hasCookie\":false},{\"id\":\"rd1\",\"platform\":\"reddit\",\"username\":\"ribbon_r\",\"totalKarma\":1,\"hasCookie\":true},{\"id\":\"rd2\",\"platform\":\"reddit\",\"username\":\"nocookie\",\"hasCookie\":false},{\"id\":\"yt2\",\"platform\":\"youtube\",\"channelId\":\"UCmissingmissingmissing0\",\"hasCookie\":false}]"
+ "body": "[{\"id\":\"yt1\",\"platform\":\"youtube\",\"channelId\":\"UCaaaaaaaaaaaaaaaaaaaaaa\",\"title\":\"Old title\",\"subscriberCount\":1,\"hasCookie\":false},{\"id\":\"ig1\",\"platform\":\"instagram\",\"igUserId\":\"1789\",\"username\":\"ribbon\",\"tokenExpiresAt\":\"2026-09-05T00:00:00.000Z\",\"followersCount\":1,\"hasCookie\":false},{\"id\":\"ig2\",\"platform\":\"instagram\",\"igUserId\":\"2000\",\"username\":\"notoken\",\"hasCookie\":false},{\"id\":\"old1\",\"platform\":\"retired\",\"username\":\"old_profile\",\"hasCookie\":false},{\"id\":\"yt2\",\"platform\":\"youtube\",\"channelId\":\"UCmissingmissingmissing0\",\"hasCookie\":false}]"
},
{
"status": 200,
diff --git a/backend/tests/fixtures/accountsRoutes.refreshAll.golden.json b/backend/tests/fixtures/accountsRoutes.refreshAll.golden.json
index 157b0d8..604a048 100644
--- a/backend/tests/fixtures/accountsRoutes.refreshAll.golden.json
+++ b/backend/tests/fixtures/accountsRoutes.refreshAll.golden.json
@@ -2,15 +2,15 @@
"responses": [
{
"status": 200,
- "body": "{\"success\":true,\"accounts\":[{\"id\":\"yt1\",\"platform\":\"youtube\",\"channelId\":\"UCaaaaaaaaaaaaaaaaaaaaaa\",\"title\":\"Channel UCaa\",\"subscriberCount\":500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"viewCount\":9000,\"videoCount\":12,\"thumbnails\":{\"default\":\"d\",\"medium\":\"m\",\"high\":\"h\"},\"hasCookie\":false},{\"id\":\"ig1\",\"platform\":\"instagram\",\"igUserId\":\"1789\",\"username\":\"ribbon\",\"tokenExpiresAt\":\"2026-09-05T00:00:00.000Z\",\"followersCount\":2500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"followsCount\":10,\"mediaCount\":140,\"title\":\"Ribbon\",\"profilePictureUrl\":\"https://p\",\"hasCookie\":false},{\"id\":\"ig2\",\"platform\":\"instagram\",\"igUserId\":\"2000\",\"username\":\"notoken\",\"hasCookie\":false},{\"id\":\"rd1\",\"platform\":\"reddit\",\"username\":\"ribbon_r\",\"totalKarma\":70,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"postKarma\":50,\"commentKarma\":20,\"iconUrl\":\"https://i?a=1&b=2\",\"hasCookie\":true},{\"id\":\"rd2\",\"platform\":\"reddit\",\"username\":\"nocookie\",\"hasCookie\":false},{\"id\":\"yt2\",\"platform\":\"youtube\",\"channelId\":\"UCmissingmissingmissing0\",\"hasCookie\":false}],\"results\":[{\"id\":\"yt1\",\"success\":true},{\"id\":\"ig1\",\"success\":true},{\"id\":\"ig2\",\"success\":false,\"error\":\"No access token stored - reconnect this Instagram account\"},{\"id\":\"rd1\",\"success\":true},{\"id\":\"rd2\",\"success\":false,\"error\":\"No session cookie stored - re-add this account with a session cookie from reddit.com DevTools\"},{\"id\":\"yt2\",\"success\":false,\"error\":\"Channel not found\"}],\"updatedAt\":\"2026-09-01T12:00:00.000Z\"}"
+ "body": "{\"success\":true,\"accounts\":[{\"id\":\"yt1\",\"platform\":\"youtube\",\"channelId\":\"UCaaaaaaaaaaaaaaaaaaaaaa\",\"title\":\"Channel UCaa\",\"subscriberCount\":500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"viewCount\":9000,\"videoCount\":12,\"thumbnails\":{\"default\":\"d\",\"medium\":\"m\",\"high\":\"h\"},\"hasCookie\":false},{\"id\":\"ig1\",\"platform\":\"instagram\",\"igUserId\":\"1789\",\"username\":\"ribbon\",\"tokenExpiresAt\":\"2026-09-05T00:00:00.000Z\",\"followersCount\":2500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"followsCount\":10,\"mediaCount\":140,\"title\":\"Ribbon\",\"profilePictureUrl\":\"https://p\",\"hasCookie\":false},{\"id\":\"ig2\",\"platform\":\"instagram\",\"igUserId\":\"2000\",\"username\":\"notoken\",\"hasCookie\":false},{\"id\":\"old1\",\"platform\":\"retired\",\"username\":\"old_profile\",\"hasCookie\":false},{\"id\":\"yt2\",\"platform\":\"youtube\",\"channelId\":\"UCmissingmissingmissing0\",\"hasCookie\":false}],\"results\":[{\"id\":\"yt1\",\"success\":true},{\"id\":\"ig1\",\"success\":true},{\"id\":\"ig2\",\"success\":false,\"error\":\"No access token stored - reconnect this Instagram account\"},{\"id\":\"old1\",\"success\":false,\"error\":\"No YouTube channel ID stored - delete this channel and add it again\"},{\"id\":\"yt2\",\"success\":false,\"error\":\"Channel not found\"}],\"updatedAt\":\"2026-09-01T12:00:00.000Z\"}"
},
{
"status": 200,
- "body": "{\"success\":true,\"accounts\":[{\"id\":\"yt1\",\"platform\":\"youtube\",\"channelId\":\"UCaaaaaaaaaaaaaaaaaaaaaa\",\"title\":\"Channel UCaa\",\"subscriberCount\":500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"viewCount\":9000,\"videoCount\":12,\"thumbnails\":{\"default\":\"d\",\"medium\":\"m\",\"high\":\"h\"},\"hasCookie\":false},{\"id\":\"ig1\",\"platform\":\"instagram\",\"igUserId\":\"1789\",\"username\":\"ribbon\",\"tokenExpiresAt\":\"2026-09-05T00:00:00.000Z\",\"followersCount\":2500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"followsCount\":10,\"mediaCount\":140,\"title\":\"Ribbon\",\"profilePictureUrl\":\"https://p\",\"hasCookie\":false},{\"id\":\"ig2\",\"platform\":\"instagram\",\"igUserId\":\"2000\",\"username\":\"notoken\",\"hasCookie\":false},{\"id\":\"rd1\",\"platform\":\"reddit\",\"username\":\"ribbon_r\",\"totalKarma\":70,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"postKarma\":50,\"commentKarma\":20,\"iconUrl\":\"https://i?a=1&b=2\",\"hasCookie\":true},{\"id\":\"rd2\",\"platform\":\"reddit\",\"username\":\"nocookie\",\"hasCookie\":false},{\"id\":\"yt2\",\"platform\":\"youtube\",\"channelId\":\"UCmissingmissingmissing0\",\"hasCookie\":false}],\"results\":[{\"id\":\"yt1\",\"success\":false,\"error\":\"YouTube API key not configured on server\"},{\"id\":\"ig1\",\"success\":true},{\"id\":\"ig2\",\"success\":false,\"error\":\"No access token stored - reconnect this Instagram account\"},{\"id\":\"rd1\",\"success\":true},{\"id\":\"rd2\",\"success\":false,\"error\":\"No session cookie stored - re-add this account with a session cookie from reddit.com DevTools\"},{\"id\":\"yt2\",\"success\":false,\"error\":\"YouTube API key not configured on server\"}],\"updatedAt\":\"2026-09-01T12:00:00.000Z\"}"
+ "body": "{\"success\":true,\"accounts\":[{\"id\":\"yt1\",\"platform\":\"youtube\",\"channelId\":\"UCaaaaaaaaaaaaaaaaaaaaaa\",\"title\":\"Channel UCaa\",\"subscriberCount\":500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"viewCount\":9000,\"videoCount\":12,\"thumbnails\":{\"default\":\"d\",\"medium\":\"m\",\"high\":\"h\"},\"hasCookie\":false},{\"id\":\"ig1\",\"platform\":\"instagram\",\"igUserId\":\"1789\",\"username\":\"ribbon\",\"tokenExpiresAt\":\"2026-09-05T00:00:00.000Z\",\"followersCount\":2500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"followsCount\":10,\"mediaCount\":140,\"title\":\"Ribbon\",\"profilePictureUrl\":\"https://p\",\"hasCookie\":false},{\"id\":\"ig2\",\"platform\":\"instagram\",\"igUserId\":\"2000\",\"username\":\"notoken\",\"hasCookie\":false},{\"id\":\"old1\",\"platform\":\"retired\",\"username\":\"old_profile\",\"hasCookie\":false},{\"id\":\"yt2\",\"platform\":\"youtube\",\"channelId\":\"UCmissingmissingmissing0\",\"hasCookie\":false}],\"results\":[{\"id\":\"yt1\",\"success\":false,\"error\":\"YouTube API key not configured on server\"},{\"id\":\"ig1\",\"success\":true},{\"id\":\"ig2\",\"success\":false,\"error\":\"No access token stored - reconnect this Instagram account\"},{\"id\":\"old1\",\"success\":false,\"error\":\"No YouTube channel ID stored - delete this channel and add it again\"},{\"id\":\"yt2\",\"success\":false,\"error\":\"YouTube API key not configured on server\"}],\"updatedAt\":\"2026-09-01T12:00:00.000Z\"}"
},
{
"status": 200,
- "body": "{\"success\":true,\"accounts\":[{\"id\":\"yt1\",\"platform\":\"youtube\",\"channelId\":\"UCaaaaaaaaaaaaaaaaaaaaaa\",\"title\":\"Channel UCaa\",\"subscriberCount\":500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"viewCount\":9000,\"videoCount\":12,\"thumbnails\":{\"default\":\"d\",\"medium\":\"m\",\"high\":\"h\"},\"hasCookie\":false},{\"id\":\"ig1\",\"platform\":\"instagram\",\"igUserId\":\"1789\",\"username\":\"ribbon\",\"tokenExpiresAt\":\"2026-09-05T00:00:00.000Z\",\"followersCount\":2500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"followsCount\":10,\"mediaCount\":140,\"title\":\"Ribbon\",\"profilePictureUrl\":\"https://p\",\"hasCookie\":false},{\"id\":\"ig2\",\"platform\":\"instagram\",\"igUserId\":\"2000\",\"username\":\"notoken\",\"hasCookie\":false},{\"id\":\"rd1\",\"platform\":\"reddit\",\"username\":\"ribbon_r\",\"totalKarma\":70,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"postKarma\":50,\"commentKarma\":20,\"iconUrl\":\"https://i?a=1&b=2\",\"hasCookie\":true},{\"id\":\"rd2\",\"platform\":\"reddit\",\"username\":\"nocookie\",\"hasCookie\":false},{\"id\":\"yt2\",\"platform\":\"youtube\",\"channelId\":\"UCmissingmissingmissing0\",\"hasCookie\":false}],\"results\":[{\"id\":\"yt1\",\"success\":true},{\"id\":\"ig1\",\"success\":true},{\"id\":\"ig2\",\"success\":false,\"error\":\"No access token stored - reconnect this Instagram account\"},{\"id\":\"rd1\",\"success\":true},{\"id\":\"rd2\",\"success\":false,\"error\":\"No session cookie stored - re-add this account with a session cookie from reddit.com DevTools\"},{\"id\":\"yt2\",\"success\":false,\"error\":\"Channel not found\"}],\"updatedAt\":\"2026-09-01T12:00:00.000Z\"}"
+ "body": "{\"success\":true,\"accounts\":[{\"id\":\"yt1\",\"platform\":\"youtube\",\"channelId\":\"UCaaaaaaaaaaaaaaaaaaaaaa\",\"title\":\"Channel UCaa\",\"subscriberCount\":500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"viewCount\":9000,\"videoCount\":12,\"thumbnails\":{\"default\":\"d\",\"medium\":\"m\",\"high\":\"h\"},\"hasCookie\":false},{\"id\":\"ig1\",\"platform\":\"instagram\",\"igUserId\":\"1789\",\"username\":\"ribbon\",\"tokenExpiresAt\":\"2026-09-05T00:00:00.000Z\",\"followersCount\":2500,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"followsCount\":10,\"mediaCount\":140,\"title\":\"Ribbon\",\"profilePictureUrl\":\"https://p\",\"hasCookie\":false},{\"id\":\"ig2\",\"platform\":\"instagram\",\"igUserId\":\"2000\",\"username\":\"notoken\",\"hasCookie\":false},{\"id\":\"old1\",\"platform\":\"retired\",\"username\":\"old_profile\",\"hasCookie\":false},{\"id\":\"yt2\",\"platform\":\"youtube\",\"channelId\":\"UCmissingmissingmissing0\",\"hasCookie\":false}],\"results\":[{\"id\":\"yt1\",\"success\":true},{\"id\":\"ig1\",\"success\":true},{\"id\":\"ig2\",\"success\":false,\"error\":\"No access token stored - reconnect this Instagram account\"},{\"id\":\"old1\",\"success\":false,\"error\":\"No YouTube channel ID stored - delete this channel and add it again\"},{\"id\":\"yt2\",\"success\":false,\"error\":\"Channel not found\"}],\"updatedAt\":\"2026-09-01T12:00:00.000Z\"}"
}
],
"requests": [
@@ -22,15 +22,6 @@
"url": "https://graph.instagram.com/v25.0/1789?access_token=IGTOKEN&fields=user_id%2Cusername%2Cname%2Cprofile_picture_url%2Cfollowers_count%2Cfollows_count%2Cmedia_count%2Cbiography%2Cwebsite",
"method": "GET"
},
- {
- "url": "https://www.reddit.com/user/ribbon_r/about.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json",
- "Cookie": "reddit_session=COOKIE"
- }
- },
{
"url": "https://www.googleapis.com/youtube/v3/channels?part=snippet%2Cstatistics%2CcontentDetails%2CbrandingSettings%2Cstatus%2CtopicDetails&id=UCmissingmissingmissing0&key=YTKEY",
"method": "GET"
@@ -39,15 +30,6 @@
"url": "https://graph.instagram.com/v25.0/1789?access_token=IGTOKEN&fields=user_id%2Cusername%2Cname%2Cprofile_picture_url%2Cfollowers_count%2Cfollows_count%2Cmedia_count%2Cbiography%2Cwebsite",
"method": "GET"
},
- {
- "url": "https://www.reddit.com/user/ribbon_r/about.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json",
- "Cookie": "reddit_session=COOKIE"
- }
- },
{
"url": "https://www.googleapis.com/youtube/v3/channels?part=snippet%2Cstatistics%2CcontentDetails%2CbrandingSettings%2Cstatus%2CtopicDetails&id=UCaaaaaaaaaaaaaaaaaaaaaa&key=PLAINKEY",
"method": "GET"
@@ -56,15 +38,6 @@
"url": "https://graph.instagram.com/v25.0/1789?access_token=IGTOKEN&fields=user_id%2Cusername%2Cname%2Cprofile_picture_url%2Cfollowers_count%2Cfollows_count%2Cmedia_count%2Cbiography%2Cwebsite",
"method": "GET"
},
- {
- "url": "https://www.reddit.com/user/ribbon_r/about.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json",
- "Cookie": "reddit_session=COOKIE"
- }
- },
{
"url": "https://www.googleapis.com/youtube/v3/channels?part=snippet%2Cstatistics%2CcontentDetails%2CbrandingSettings%2Cstatus%2CtopicDetails&id=UCmissingmissingmissing0&key=PLAINKEY",
"method": "GET"
@@ -121,22 +94,6 @@
},
"filters": []
},
- {
- "type": "rpc",
- "table": "merge_account_data",
- "values": {
- "p_id": "rd1",
- "p_user_id": "user-1",
- "p_patch": {
- "lastUpdated": "2026-09-01T12:00:00.000Z",
- "totalKarma": 70,
- "postKarma": 50,
- "commentKarma": 20,
- "iconUrl": "https://i?a=1&b=2"
- }
- },
- "filters": []
- },
{
"type": "select",
"table": "accounts",
@@ -177,22 +134,6 @@
},
"filters": []
},
- {
- "type": "rpc",
- "table": "merge_account_data",
- "values": {
- "p_id": "rd1",
- "p_user_id": "user-1",
- "p_patch": {
- "lastUpdated": "2026-09-01T12:00:00.000Z",
- "totalKarma": 70,
- "postKarma": 50,
- "commentKarma": 20,
- "iconUrl": "https://i?a=1&b=2"
- }
- },
- "filters": []
- },
{
"type": "select",
"table": "accounts",
@@ -254,22 +195,6 @@
},
"filters": []
},
- {
- "type": "rpc",
- "table": "merge_account_data",
- "values": {
- "p_id": "rd1",
- "p_user_id": "user-1",
- "p_patch": {
- "lastUpdated": "2026-09-01T12:00:00.000Z",
- "totalKarma": 70,
- "postKarma": 50,
- "commentKarma": 20,
- "iconUrl": "https://i?a=1&b=2"
- }
- },
- "filters": []
- },
{
"type": "select",
"table": "accounts",
diff --git a/backend/tests/fixtures/accountsRoutes.refreshOne.golden.json b/backend/tests/fixtures/accountsRoutes.refreshOne.golden.json
index f6b0777..72f6447 100644
--- a/backend/tests/fixtures/accountsRoutes.refreshOne.golden.json
+++ b/backend/tests/fixtures/accountsRoutes.refreshOne.golden.json
@@ -12,13 +12,9 @@
"status": 400,
"body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"No access token stored - reconnect this Instagram account\",\"requestId\":\"req-test\"}"
},
- {
- "status": 200,
- "body": "{\"success\":true,\"account\":{\"id\":\"rd1\",\"platform\":\"reddit\",\"username\":\"ribbon_r\",\"totalKarma\":70,\"lastUpdated\":\"2026-09-01T12:00:00.000Z\",\"postKarma\":50,\"commentKarma\":20,\"iconUrl\":\"https://i?a=1&b=2\",\"hasCookie\":true}}"
- },
{
"status": 400,
- "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"No session cookie stored - re-add this account with a session cookie from reddit.com DevTools\",\"requestId\":\"req-test\"}"
+ "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"No YouTube channel ID stored - delete this channel and add it again\",\"requestId\":\"req-test\"}"
},
{
"status": 200,
@@ -62,15 +58,6 @@
"url": "https://graph.instagram.com/v25.0/1789?access_token=IGTOKEN&fields=user_id%2Cusername%2Cname%2Cprofile_picture_url%2Cfollowers_count%2Cfollows_count%2Cmedia_count%2Cbiography%2Cwebsite",
"method": "GET"
},
- {
- "url": "https://www.reddit.com/user/ribbon_r/about.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json",
- "Cookie": "reddit_session=COOKIE"
- }
- },
{
"url": "https://www.googleapis.com/youtube/v3/channels?part=snippet%2Cstatistics%2CcontentDetails%2CbrandingSettings%2Cstatus%2CtopicDetails&id=UCaaaaaaaaaaaaaaaaaaaaaa&key=YTKEY",
"method": "GET"
@@ -161,38 +148,7 @@
"filters": [
[
"id",
- "rd1"
- ],
- [
- "user_id",
- "user-1"
- ]
- ]
- },
- {
- "type": "rpc",
- "table": "merge_account_data",
- "values": {
- "p_id": "rd1",
- "p_user_id": "user-1",
- "p_patch": {
- "lastUpdated": "2026-09-01T12:00:00.000Z",
- "totalKarma": 70,
- "postKarma": 50,
- "commentKarma": 20,
- "iconUrl": "https://i?a=1&b=2"
- }
- },
- "filters": []
- },
- {
- "type": "select",
- "table": "accounts",
- "columns": "id, platform, data",
- "filters": [
- [
- "id",
- "rd2"
+ "old1"
],
[
"user_id",
@@ -310,7 +266,7 @@
"filters": [
[
"id",
- "rd1"
+ "yt1"
],
[
"user_id",
diff --git a/backend/tests/middleware/rateLimit.test.ts b/backend/tests/middleware/rateLimit.test.ts
index dbf38fa..9c6345e 100644
--- a/backend/tests/middleware/rateLimit.test.ts
+++ b/backend/tests/middleware/rateLimit.test.ts
@@ -123,7 +123,6 @@ test('quota and publish routes match the endpoints that spend platform API calls
const quota = (method: string, path: string) => matchesRoute(QUOTA_ROUTES, method, path);
assert.equal(quota('POST', '/api/accounts'), true);
assert.equal(quota('GET', '/api/accounts'), false);
- assert.equal(quota('POST', '/api/accounts/reddit'), true);
assert.equal(quota('POST', '/api/accounts/instagram'), true);
assert.equal(quota('POST', '/api/accounts/refresh-all'), true);
assert.equal(quota('POST', '/api/accounts/abc123/refresh'), true);
diff --git a/backend/tests/repositories/accountRepository.test.ts b/backend/tests/repositories/accountRepository.test.ts
index 515a7cb..7631867 100644
--- a/backend/tests/repositories/accountRepository.test.ts
+++ b/backend/tests/repositories/accountRepository.test.ts
@@ -7,22 +7,22 @@ import type { SupabaseClient } from '../../types/app.ts';
const ROWS = [
accountRow({ id: 'a1', platform: 'youtube', title: 'Mine' }),
- accountRow({ id: 'a2', platform: 'reddit', username: 'theirs' }, 'user-2'),
+ accountRow({ id: 'a2', platform: 'instagram', username: 'theirs' }, 'user-2'),
];
describe('account repository', () => {
test('user methods only see the user\'s rows; system methods see every row', async () => {
const accounts = createAccountRepository(fakeSupabase(ROWS));
assert.deepEqual((await accounts.listForUser('user-1')).map(account => account.id), ['a1']);
- assert.deepEqual((await accounts.listByPlatform('reddit')).map(account => account.id), ['a2']);
+ assert.deepEqual((await accounts.listByPlatform('instagram')).map(account => account.id), ['a2']);
assert.equal(await accounts.findForUser('a2', 'user-1'), null);
- assert.deepEqual(await accounts.findById('a2'), { id: 'a2', platform: 'reddit', username: 'theirs' });
+ assert.deepEqual(await accounts.findById('a2'), { id: 'a2', platform: 'instagram', username: 'theirs' });
});
test('an update is one merge in the database that keeps the platform and the fields it does not name', async () => {
const db = fakeSupabase(ROWS);
const accounts = createAccountRepository(db);
- await accounts.updateForUser('a1', { subscriberCount: 5, platform: 'reddit', title: undefined }, 'user-1');
+ await accounts.updateForUser('a1', { subscriberCount: 5, platform: 'instagram', title: undefined }, 'user-1');
assert.deepEqual(await accounts.findForUser('a1', 'user-1'), { id: 'a1', platform: 'youtube', title: 'Mine', subscriberCount: 5 });
assert.deepEqual(db.calls[0], {
type: 'rpc', table: 'merge_account_data', filters: [],
@@ -32,8 +32,8 @@ describe('account repository', () => {
test('the cron form of an update reaches any user\'s account', async () => {
const db = fakeSupabase(ROWS);
- await createAccountRepository(db).updateById('a2', { cookie: 'new' });
- assert.equal((await createAccountRepository(db).findById('a2'))?.cookie, 'new');
+ await createAccountRepository(db).updateById('a2', { accessToken: 'new' });
+ assert.equal((await createAccountRepository(db).findById('a2'))?.accessToken, 'new');
});
test('updating an account the user does not own is not found', async () => {
diff --git a/backend/tests/routes/accountRoutes.test.ts b/backend/tests/routes/accountRoutes.test.ts
index d10e903..487b11e 100644
--- a/backend/tests/routes/accountRoutes.test.ts
+++ b/backend/tests/routes/accountRoutes.test.ts
@@ -24,8 +24,8 @@ const storedAccounts = [
accountRow({ id: 'yt1', platform: 'youtube', channelId: CHANNEL_A, title: 'Old title', subscriberCount: 1 }),
accountRow({ id: 'ig1', platform: 'instagram', igUserId: '1789', username: 'ribbon', accessToken: 'IGTOKEN', tokenExpiresAt: '2026-09-05T00:00:00.000Z', followersCount: 1 }),
accountRow({ id: 'ig2', platform: 'instagram', igUserId: '2000', username: 'notoken' }),
- accountRow({ id: 'rd1', platform: 'reddit', username: 'ribbon_r', cookie: 'COOKIE', totalKarma: 1 }),
- accountRow({ id: 'rd2', platform: 'reddit', username: 'nocookie' }),
+ // a platform Twiligent no longer supports; the app never reads its rows
+ accountRow({ id: 'old1', platform: 'retired', username: 'old_profile' }),
accountRow({ id: 'yt2', platform: 'youtube', channelId: 'UCmissingmissingmissing0' }),
accountRow({ id: 'other', platform: 'youtube', channelId: CHANNEL_NEW }, 'user-2'),
];
@@ -70,11 +70,6 @@ function instagramReply(url: URL) {
function platformServer(request: RecordedRequest) {
const url = new URL(request.url);
if (url.hostname === 'graph.instagram.com') return instagramReply(url);
- if (url.hostname === 'www.reddit.com') {
- const username = url.pathname.split('/')[2];
- if (username === 'missing') return reply({}, 404, 'Not Found');
- return reply({ data: { name: username === 'ribbon_r' ? 'ribbon_r' : 'NewUser', total_karma: 70, link_karma: 50, comment_karma: 20, icon_img: 'https://i?a=1&amp;b=2', created_utc: 1600000000 } });
- }
const params = url.searchParams;
if (params.get('forHandle')) return reply({ items: [{ id: params.get('forHandle') === 'existing' ? CHANNEL_A : CHANNEL_NEW }] });
if (params.get('forUsername') || params.get('q')) return reply({ items: [] });
@@ -133,16 +128,6 @@ describe('accounts routes golden output', () => {
]), 'accountsRoutes.addYouTube');
});
- test('adds Reddit accounts and rejects missing fields and duplicates', async () => {
- assertGolden(await runScenario([
- ['POST', '/accounts/reddit', { cookie: 'C' }],
- ['POST', '/accounts/reddit', { username: 'someone' }],
- ['POST', '/accounts/reddit', { username: 'U/NewUser ', cookie: 'NEWCOOKIE' }],
- ['POST', '/accounts/reddit', { username: 'ribbon_r', cookie: 'C2' }],
- ['POST', '/accounts/reddit', { username: 'missing', cookie: 'C3' }],
- ]), 'accountsRoutes.addReddit');
- });
-
test('adds Instagram accounts with and without a long-lived exchange', async () => {
assertGolden(await runScenario([
['POST', '/accounts/instagram', {}],
@@ -168,14 +153,13 @@ describe('accounts routes golden output', () => {
['POST', '/accounts/nope/refresh'],
['POST', '/accounts/ig1/refresh'],
['POST', '/accounts/ig2/refresh'],
- ['POST', '/accounts/rd1/refresh'],
- ['POST', '/accounts/rd2/refresh'],
+ ['POST', '/accounts/old1/refresh'],
['POST', '/accounts/yt1/refresh'],
['POST', '/accounts/yt1/refresh', undefined, {}],
['POST', '/accounts/yt2/refresh'],
['POST', '/accounts/other/refresh'],
['POST', '/accounts/nope/refresh-ig-token'],
- ['POST', '/accounts/rd1/refresh-ig-token'],
+ ['POST', '/accounts/yt1/refresh-ig-token'],
['POST', '/accounts/ig2/refresh-ig-token'],
['POST', '/accounts/ig1/refresh-ig-token'],
['POST', '/accounts/ig1/refresh-ig-token'],
@@ -186,7 +170,8 @@ describe('accounts routes golden output', () => {
assertGolden(await runScenario([
['DELETE', '/accounts/nope'],
['DELETE', '/accounts/other'],
- ['DELETE', '/accounts/rd2'],
+ ['DELETE', '/accounts/old1'],
+ ['DELETE', '/accounts/yt2'],
['GET', '/accounts'],
]), 'accountsRoutes.delete');
});
@@ -195,7 +180,6 @@ describe('accounts routes golden output', () => {
assertGolden(await runScenario([
['GET', '/accounts'],
['POST', '/accounts', { input: '@creator' }],
- ['POST', '/accounts/reddit', { username: 'NewUser', cookie: 'C' }],
['POST', '/accounts/instagram', { accessToken: 'IGTOKEN' }, {}],
['POST', '/accounts/refresh-all'],
['POST', '/accounts/ig1/refresh'],
@@ -204,21 +188,21 @@ describe('accounts routes golden output', () => {
], { supabase: brokenSupabase }), 'accountsRoutes.dbFailure');
});
- test('refreshing an account without a channel id or username fails before calling the platform', async () => {
+ test('refreshing an account without a channel id or token fails before calling the platform', async () => {
const supabase = fakeSupabase([
accountRow({ id: 'ytOld', platform: 'youtube', title: 'No id' }),
- accountRow({ id: 'rdOld', platform: 'reddit', cookie: 'COOKIE' }),
+ accountRow({ id: 'igOld', platform: 'instagram', igUserId: '1' }),
]);
const app = mountWithContext(app => app.route('/', accountsRouter), { supabase, redis: fakeRedis(), userId: 'user-1' });
const single = async (id: string) => JSON.parse((await callRoute(app, 'POST', `/accounts/${id}/refresh`, { env: ENV })).body) as unknown;
const failure = (message: string) => ({ success: false, code: 'VALIDATION_ERROR', message, requestId: 'req-test' });
assert.deepEqual(await single('ytOld'), failure('No YouTube channel ID stored - delete this channel and add it again'));
- assert.deepEqual(await single('rdOld'), failure('No Reddit username stored - delete this account and add it again'));
+ assert.deepEqual(await single('igOld'), failure('No access token stored - reconnect this Instagram account'));
const all = JSON.parse((await callRoute(app, 'POST', '/accounts/refresh-all', { env: ENV })).body) as { results: unknown[] };
assert.deepEqual(all.results, [
{ id: 'ytOld', success: false, error: 'No YouTube channel ID stored - delete this channel and add it again' },
- { id: 'rdOld', success: false, error: 'No Reddit username stored - delete this account and add it again' },
+ { id: 'igOld', success: false, error: 'No access token stored - reconnect this Instagram account' },
]);
assert.deepEqual(fetchMock!.requests, []);
});
diff --git a/backend/tests/routes/index.test.ts b/backend/tests/routes/index.test.ts
index 7c55be4..e98232a 100644
--- a/backend/tests/routes/index.test.ts
+++ b/backend/tests/routes/index.test.ts
@@ -20,4 +20,8 @@ describe('The protected route table', () => {
assert.deepEqual(await call('GET', path), notFound('GET', path));
}
});
+
+ test('no longer answers the removed Reddit account route', async () => {
+ assert.deepEqual(await call('POST', '/accounts/reddit', { username: 'someone', cookie: 'C' }), notFound('POST', '/accounts/reddit'));
+ });
});
diff --git a/backend/tests/services/accountFactory.test.ts b/backend/tests/services/accountFactory.test.ts
index 8730154..361b64f 100644
--- a/backend/tests/services/accountFactory.test.ts
+++ b/backend/tests/services/accountFactory.test.ts
@@ -1,10 +1,9 @@
import { test, describe, before, after, beforeEach, afterEach, mock } from 'node:test';
import assert from 'node:assert/strict';
import {
- tokenExpiryIso, buildYouTubeAccount, buildRedditAccount, buildInstagramAccount,
+ tokenExpiryIso, buildYouTubeAccount, buildInstagramAccount,
} from '../../services/accountFactory.ts';
import type { YouTubeChannelData } from '../../../shared/types/youtube.ts';
-import type { RedditProfile } from '../../../shared/types/reddit.ts';
const FIXED_NOW = Date.parse('2026-09-01T12:00:00Z');
const NOW_ISO = '2026-09-01T12:00:00.000Z';
@@ -39,15 +38,6 @@ describe('accountFactory', () => {
assert.equal(account.lastUpdated, NOW_ISO);
});
- test('buildRedditAccount keeps the cookie and prefixes the title', () => {
- const profile = { username: 'ribbon', totalKarma: 3, postKarma: 2, commentKarma: 1, iconUrl: 'i', createdAt: 'c', isGold: true };
- assert.deepStrictEqual(buildRedditAccount(profile as RedditProfile, 'COOKIE'), {
- id: ACCOUNT_ID, platform: 'reddit', username: 'ribbon', title: 'u/ribbon',
- totalKarma: 3, postKarma: 2, commentKarma: 1, iconUrl: 'i', createdAt: 'c', cookie: 'COOKIE',
- addedAt: NOW_ISO, lastUpdated: NOW_ISO,
- });
- });
-
test('buildInstagramAccount falls back to the username as title and sets the expiry', () => {
const profile = {
igUserId: '9', username: 'ribbon', name: '', biography: 'b', website: 'w', profilePictureUrl: 'p',
diff --git a/backend/tests/services/accountService.test.ts b/backend/tests/services/accountService.test.ts
index e010b18..67738b1 100644
--- a/backend/tests/services/accountService.test.ts
+++ b/backend/tests/services/accountService.test.ts
@@ -27,23 +27,23 @@ function service(accounts: AccountRepository) {
});
}
-function redditAnswers(t: { after(fn: () => void): void }) {
- const fetch = mock.method(globalThis, 'fetch', async () => Response.json({ data: { name: 'ribbon_r', total_karma: 3 } }));
+function instagramAnswers(t: { after(fn: () => void): void }) {
+ const fetch = mock.method(globalThis, 'fetch', async () => Response.json({ user_id: '1789', username: 'ribbon' }));
t.after(() => fetch.mock.restore());
}
test('an add that loses a race to the same account gets the usual already added answer, not a database error', async t => {
- redditAnswers(t);
+ instagramAnswers(t);
const accounts = accountsFailingWith({ code: '23505', message: 'duplicate key value violates unique constraint "accounts_identity_key"' });
- await assert.rejects(service(accounts).addReddit('user-1', { username: 'ribbon_r', cookie: '' }), (err: Error) => {
+ await assert.rejects(service(accounts).addInstagram('user-1', 'IGTOKEN'), (err: Error) => {
assert.ok(err instanceof ConflictError);
- assert.equal(err.message, 'This Reddit account is already added');
+ assert.equal(err.message, 'This Instagram account is already added');
return true;
});
});
test('any other failed insert stays a database error', async t => {
- redditAnswers(t);
+ instagramAnswers(t);
const accounts = accountsFailingWith({ code: '08006', message: 'connection failure' });
- await assert.rejects(service(accounts).addReddit('user-1', { username: 'ribbon_r', cookie: '' }), DatabaseError);
+ await assert.rejects(service(accounts).addInstagram('user-1', 'IGTOKEN'), DatabaseError);
});
diff --git a/backend/tests/validators/accountValidators.test.ts b/backend/tests/validators/accountValidators.test.ts
index 86b5e73..fd654a3 100644
--- a/backend/tests/validators/accountValidators.test.ts
+++ b/backend/tests/validators/accountValidators.test.ts
@@ -1,18 +1,14 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { normalizeRedditUsername, parseRedditAccount } from '../../validators/accountValidators.ts';
+import { parseChannelInput, parseInstagramToken } from '../../validators/accountValidators.ts';
import { ValidationError } from '../../lib/errors.ts';
-test('a Reddit username is taken from u/name, @name or a pasted profile address', () => {
- assert.equal(normalizeRedditUsername(' u/spez '), 'spez');
- assert.equal(normalizeRedditUsername('/u/spez'), 'spez');
- assert.equal(normalizeRedditUsername('@spez'), 'spez');
- assert.equal(normalizeRedditUsername('https://www.reddit.com/user/spez/'), 'spez');
- assert.equal(normalizeRedditUsername('reddit.com/u/spez?sort=new'), 'spez');
- assert.equal(normalizeRedditUsername('spez'), 'spez');
+test('the channel body keeps the trimmed input and asks for one when it is missing', () => {
+ assert.deepEqual(parseChannelInput({ input: ' @creator ' }), { input: '@creator' });
+ assert.throws(() => parseChannelInput({ input: ' ' }), new ValidationError('Enter a channel URL, @handle or channel ID'));
});
-test('the Reddit account body keeps only the username and refuses one that is only a prefix', () => {
- assert.deepEqual(parseRedditAccount({ username: 'u/spez', cookie: ' abc ' }), { username: 'spez', cookie: 'abc' });
- assert.throws(() => parseRedditAccount({ username: 'u/', cookie: 'abc' }), new ValidationError('Enter the Reddit username, such as u/name'));
+test('the Instagram token body keeps the trimmed token and refuses an empty one', () => {
+ assert.deepEqual(parseInstagramToken({ accessToken: ' TOKEN ' }), { accessToken: 'TOKEN' });
+ assert.throws(() => parseInstagramToken({}), new ValidationError('Access token is required'));
});
diff --git a/backend/validators/accountValidators.ts b/backend/validators/accountValidators.ts
index f7e3104..158d0ab 100644
--- a/backend/validators/accountValidators.ts
+++ b/backend/validators/accountValidators.ts
@@ -1,7 +1,5 @@
-import { ValidationError } from '../lib/errors.ts';
import { requiredString } from './fields.ts';
import type { Fields } from './fields.ts';
-import type { RedditAccountInput } from '../services/accountService.ts';
export interface ChannelInput {
input: string;
@@ -15,22 +13,6 @@ export function parseChannelInput(body: Fields): ChannelInput {
return { input: requiredString(body, 'input', 'Enter a channel URL, @handle or channel ID') };
}
-// people paste "u/name", "/u/name", "@name" or the address of their profile; only the name is kept
-export function normalizeRedditUsername(input: string): string {
- const text = input.trim();
- const fromUrl = text.match(/reddit\.com\/(?:user|u)\/([^/?#\s]+)/i);
- return (fromUrl ? fromUrl[1] : text).replace(/^\/?u\//i, '').replace(/^@/, '').trim();
-}
-
-export function parseRedditAccount(body: Fields): RedditAccountInput {
- const username = normalizeRedditUsername(requiredString(body, 'username', 'Enter the Reddit username, such as u/name'));
- if (!username) throw new ValidationError('Enter the Reddit username, such as u/name');
- return {
- username,
- cookie: requiredString(body, 'cookie', 'Session cookie is required - open reddit.com in your browser, copy the reddit_session value from DevTools (Application > Cookies > reddit.com), and paste it here'),
- };
-}
-
export function parseInstagramToken(body: Fields): InstagramTokenInput {
return { accessToken: requiredString(body, 'accessToken', 'Access token is required') };
}