Skip to content

Commit

Permalink
fix(test): add reference to user_firefox_account for test seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
kschelonka committed Oct 28, 2024
1 parent 2355bb8 commit 021c689
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions servers/user-api/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export default {
user_id: [...tables.tablesWithSensitivePii],
created_by_user_id: ['channels'],
},
// For test seeds
userPIITestSeedTables: {
user_id: [...tables.tablesWithSensitivePii, 'user_firefox_account'],
created_by_user_id: ['channels'],
},
},
sentry: {
dsn: process.env.SENTRY_DSN || '',
Expand Down
26 changes: 14 additions & 12 deletions servers/user-api/src/test/functional/seeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { writeClient as conn } from '../../database/client';
import config from '../../config';

export async function truncatePiiTables() {
const allTables = Object.entries(config.database.userPIITables).flatMap(
([_, tables]) => tables,
);
const allTables = Object.entries(
config.database.userPIITestSeedTables,
).flatMap(([_, tables]) => tables);
await Promise.all(
allTables.map((table: string) => {
return conn()(table).truncate();
Expand All @@ -26,15 +26,17 @@ export async function PiiTableSeed(user_id: number, firefox_uid: string) {
};

await Promise.all(
Object.entries(config.database.userPIITables).flatMap(([key, tables]) => {
return tables.map((tableName) => {
if (!(tableName in specialTablesSeeds)) {
return conn()(tableName).insert({ [key]: user_id });
} else {
return conn()(tableName).insert(specialTablesSeeds[tableName]);
}
});
}),
Object.entries(config.database.userPIITestSeedTables).flatMap(
([key, tables]) => {
return tables.map((tableName) => {
if (!(tableName in specialTablesSeeds)) {
return conn()(tableName).insert({ [key]: user_id });
} else {
return conn()(tableName).insert(specialTablesSeeds[tableName]);
}
});
},
),
);
}

Expand Down

0 comments on commit 021c689

Please sign in to comment.