Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
60beb3c
Initial changes
dburkhart07 Nov 9, 2025
3e6fdeb
Initial testing changes
dburkhart07 Nov 11, 2025
9e62a9a
Commit
dburkhart07 Nov 11, 2025
0971ca1
added dummy data for testing
dburkhart07 Nov 15, 2025
80ce71f
Resolved merge conflicts
dburkhart07 Nov 21, 2025
92686b6
Resolved merge conflicts
dburkhart07 Nov 21, 2025
4d3d693
Completed proper pipeline for dummy testing data
dburkhart07 Nov 21, 2025
ec2fb63
Testing the action CI workflow
dburkhart07 Nov 21, 2025
c5c7b9b
Simplified workflow
dburkhart07 Nov 21, 2025
294e85e
Testing workflow with securing-safe-food-test deleted
dburkhart07 Nov 21, 2025
a474507
Updated README
dburkhart07 Nov 21, 2025
3cc1010
Restored theme.ts
dburkhart07 Nov 21, 2025
dc6aa8c
Final commit
dburkhart07 Nov 21, 2025
2f575a3
Moved migrations to constant file for easy refactoring
dburkhart07 Jan 30, 2026
85ff2df
prettier
dburkhart07 Jan 30, 2026
e7f9c02
Merged main
dburkhart07 Jan 30, 2026
5bd6ce2
Final commit
dburkhart07 Jan 30, 2026
4f0642c
prettier
dburkhart07 Jan 30, 2026
bfcb073
Changes, still working on getting testing working
dburkhart07 Feb 1, 2026
d09f888
prettier
dburkhart07 Feb 1, 2026
050c9aa
Readjusted testing approach
dburkhart07 Feb 2, 2026
365a6d3
final commit
dburkhart07 Feb 2, 2026
509a5dd
Fixed schema migrations
dburkhart07 Feb 2, 2026
d7096af
Final commit
dburkhart07 Feb 5, 2026
2a32753
Merge branch 'main' into ddb/SSF-98-local-db-unit-testing-service-fun…
dburkhart07 Feb 5, 2026
6f61a4e
prettier
dburkhart07 Feb 5, 2026
7b3ffac
Merged main
dburkhart07 Feb 6, 2026
dbb55d7
prettier
dburkhart07 Feb 6, 2026
2752884
Fixed tests
dburkhart07 Feb 6, 2026
02293f9
prettier
dburkhart07 Feb 6, 2026
5af0eda
Final commit
dburkhart07 Feb 6, 2026
2b6004f
Fixed ci flow
dburkhart07 Feb 6, 2026
1aa5a28
Fixed ci flow
dburkhart07 Feb 6, 2026
5417581
Fixed dependencies
dburkhart07 Feb 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=securing-safe-food
DATABASE_NAME_TEST=securing-safe-food-test
DATABASE_USERNAME=postgres
DATABASE_PASSWORD=PLACEHOLDER_PASSWORD
30 changes: 30 additions & 0 deletions .github/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on: [push, pull_request]

jobs:
backend-tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_DB: securing-safe-food-test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
env:
DATABASE_HOST: 127.0.0.1
DATABASE_PORT: 5432
DATABASE_NAME_TEST: securing-safe-food-test
DATABASE_USERNAME: postgres
DATABASE_PASSWORD: postgres
NX_DAEMON: 'false'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: yarn install
- run: yarn test


113 changes: 0 additions & 113 deletions .github/workflows/ci-cd.yml

This file was deleted.

10 changes: 9 additions & 1 deletion apps/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ You can check that your database connection details are correct by running `nx s
"LOG 🚀 Application is running on: http://localhost:3000/api"
```

Finally, run `yarn run typeorm:migrate` to load all the tables into your database. If everything is set up correctly, you should see "Migration ... has been executed successfully." in the terminal.
Finally, run `yarn run typeorm:migrate` to load all the tables into your database. If everything is set up correctly, you should see "Migration ... has been executed successfully." in the terminal.

### Running backend tests

1. Create a **separate** Postgres database (for example `securing-safe-food-test`).
2. Add a `DATABASE_NAME_TEST` entry (and optionally `DATABASE_HOST/PORT/USERNAME/PASSWORD`) to your `.env` so the test data source can connect to that database.
3. Run the backend test suite with `npx jest`.

Each spec builds up the database and tables, tears it all down, and runs all the migrations on each tests. This ensures that we always have the most up to date data that we test with.
59 changes: 59 additions & 0 deletions apps/backend/src/config/migrations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { User1725726359198 } from '../migrations/1725726359198-User';
import { AddTables1726524792261 } from '../migrations/1726524792261-addTables';
import { ReviseTables1737522923066 } from '../migrations/1737522923066-reviseTables';
import { UpdateUserRole1737816745912 } from '../migrations/1737816745912-UpdateUserRole';
import { UpdatePantriesTable1737906317154 } from '../migrations/1737906317154-updatePantriesTable';
import { UpdateDonations1738697216020 } from '../migrations/1738697216020-updateDonations';
import { UpdateDonationColTypes1741708808976 } from '../migrations/1741708808976-UpdateDonationColTypes';
import { UpdatePantriesTable1738172265266 } from '../migrations/1738172265266-updatePantriesTable';
import { UpdatePantriesTable1739056029076 } from '../migrations/1739056029076-updatePantriesTable';
import { AssignmentsPantryIdNotUnique1758384669652 } from '../migrations/1758384669652-AssignmentsPantryIdNotUnique';
import { UpdateOrdersTable1740367964915 } from '../migrations/1740367964915-updateOrdersTable';
import { UpdateFoodRequests1744051370129 } from '../migrations/1744051370129-updateFoodRequests';
import { UpdateRequestTable1741571847063 } from '../migrations/1741571847063-updateRequestTable';
import { RemoveOrderIdFromRequests1744133526650 } from '../migrations/1744133526650-removeOrderIdFromRequests';
import { AddOrders1739496585940 } from '../migrations/1739496585940-addOrders';
import { AddingEnumValues1760538239997 } from '../migrations/1760538239997-AddingEnumValues';
import { UpdateColsToUseEnumType1760886499863 } from '../migrations/1760886499863-UpdateColsToUseEnumType';
import { UpdatePantriesTable1742739750279 } from '../migrations/1742739750279-updatePantriesTable';
import { RemoveOrdersDonationId1761500262238 } from '../migrations/1761500262238-RemoveOrdersDonationId';
import { AddVolunteerPantryUniqueConstraint1760033134668 } from '../migrations/1760033134668-AddVolunteerPantryUniqueConstraint';
import { AllergyFriendlyToBoolType1763963056712 } from '../migrations/1763963056712-AllergyFriendlyToBoolType';
import { UpdatePantryUserFieldsFixed1764350314832 } from '../migrations/1764350314832-UpdatePantryUserFieldsFixed';
import { RemoveMultipleVolunteerTypes1764811878152 } from '../migrations/1764811878152-RemoveMultipleVolunteerTypes';
import { RemoveUnusedStatuses1764816885341 } from '../migrations/1764816885341-RemoveUnusedStatuses';
import { UpdatePantryFields1763762628431 } from '../migrations/1763762628431-UpdatePantryFields';
import { PopulateDummyData1768501812134 } from '../migrations/1768501812134-populateDummyData';
import { RemovePantryFromOrders1769316004958 } from '../migrations/1769316004958-RemovePantryFromOrders';

const schemaMigrations = [
User1725726359198,
AddTables1726524792261,
ReviseTables1737522923066,
UpdateUserRole1737816745912,
UpdatePantriesTable1737906317154,
UpdateDonations1738697216020,
UpdateDonationColTypes1741708808976,
UpdatePantriesTable1738172265266,
UpdatePantriesTable1739056029076,
AssignmentsPantryIdNotUnique1758384669652,
AddOrders1739496585940,
UpdateOrdersTable1740367964915,
UpdateRequestTable1741571847063,
UpdateFoodRequests1744051370129,
RemoveOrderIdFromRequests1744133526650,
AddingEnumValues1760538239997,
UpdateColsToUseEnumType1760886499863,
UpdatePantriesTable1742739750279,
RemoveOrdersDonationId1761500262238,
UpdatePantryFields1763762628431,
AddVolunteerPantryUniqueConstraint1760033134668,
AllergyFriendlyToBoolType1763963056712,
UpdatePantryUserFieldsFixed1764350314832,
RemoveMultipleVolunteerTypes1764811878152,
RemoveUnusedStatuses1764816885341,
PopulateDummyData1768501812134,
RemovePantryFromOrders1769316004958,
];

export default schemaMigrations;
60 changes: 2 additions & 58 deletions apps/backend/src/config/typeorm.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
import { registerAs } from '@nestjs/config';
import { PluralNamingStrategy } from '../strategies/plural-naming.strategy';
import { DataSource, DataSourceOptions } from 'typeorm';
import { User1725726359198 } from '../migrations/1725726359198-User';
import { AddTables1726524792261 } from '../migrations/1726524792261-addTables';
import { ReviseTables1737522923066 } from '../migrations/1737522923066-reviseTables';
import { UpdateUserRole1737816745912 } from '../migrations/1737816745912-UpdateUserRole';
import { UpdatePantriesTable1737906317154 } from '../migrations/1737906317154-updatePantriesTable';
import { UpdateDonations1738697216020 } from '../migrations/1738697216020-updateDonations';
import { UpdateDonationColTypes1741708808976 } from '../migrations/1741708808976-UpdateDonationColTypes';
import { UpdatePantriesTable1738172265266 } from '../migrations/1738172265266-updatePantriesTable';
import { UpdatePantriesTable1739056029076 } from '../migrations/1739056029076-updatePantriesTable';
import { AssignmentsPantryIdNotUnique1758384669652 } from '../migrations/1758384669652-AssignmentsPantryIdNotUnique';
import { UpdateOrdersTable1740367964915 } from '../migrations/1740367964915-updateOrdersTable';
import { UpdateFoodRequests1744051370129 } from '../migrations/1744051370129-updateFoodRequests';
import { UpdateRequestTable1741571847063 } from '../migrations/1741571847063-updateRequestTable';
import { RemoveOrderIdFromRequests1744133526650 } from '../migrations/1744133526650-removeOrderIdFromRequests';
import { AddOrders1739496585940 } from '../migrations/1739496585940-addOrders';
import { AddingEnumValues1760538239997 } from '../migrations/1760538239997-AddingEnumValues';
import { UpdateColsToUseEnumType1760886499863 } from '../migrations/1760886499863-UpdateColsToUseEnumType';
import { UpdatePantriesTable1742739750279 } from '../migrations/1742739750279-updatePantriesTable';
import { RemoveOrdersDonationId1761500262238 } from '../migrations/1761500262238-RemoveOrdersDonationId';
import { AddVolunteerPantryUniqueConstraint1760033134668 } from '../migrations/1760033134668-AddVolunteerPantryUniqueConstraint';
import { AllergyFriendlyToBoolType1763963056712 } from '../migrations/1763963056712-AllergyFriendlyToBoolType';
import { UpdatePantryUserFieldsFixed1764350314832 } from '../migrations/1764350314832-UpdatePantryUserFieldsFixed';
import { RemoveMultipleVolunteerTypes1764811878152 } from '../migrations/1764811878152-RemoveMultipleVolunteerTypes';
import { RemoveUnusedStatuses1764816885341 } from '../migrations/1764816885341-RemoveUnusedStatuses';
import { UpdatePantryFields1763762628431 } from '../migrations/1763762628431-UpdatePantryFields';
import { PopulateDummyData1768501812134 } from '../migrations/1768501812134-populateDummyData';
import { RemovePantryFromOrders1769316004958 } from '../migrations/1769316004958-RemovePantryFromOrders';
import schemaMigrations from './migrations';

const config = {
type: 'postgres',
Expand All @@ -39,37 +13,7 @@ const config = {
autoLoadEntities: true,
synchronize: false,
namingStrategy: new PluralNamingStrategy(),
// Glob patterns (e.g. ../migrations/**.ts) are deprecated, so we have to manually specify each migration
// TODO: see if there's still a way to dynamically load all migrations
migrations: [
User1725726359198,
AddTables1726524792261,
ReviseTables1737522923066,
UpdateUserRole1737816745912,
UpdatePantriesTable1737906317154,
UpdateDonations1738697216020,
UpdateDonationColTypes1741708808976,
UpdatePantriesTable1738172265266,
UpdatePantriesTable1739056029076,
AssignmentsPantryIdNotUnique1758384669652,
AddOrders1739496585940,
UpdateOrdersTable1740367964915,
UpdateRequestTable1741571847063,
UpdateFoodRequests1744051370129,
RemoveOrderIdFromRequests1744133526650,
AddingEnumValues1760538239997,
UpdateColsToUseEnumType1760886499863,
UpdatePantriesTable1742739750279,
RemoveOrdersDonationId1761500262238,
UpdatePantryFields1763762628431,
AddVolunteerPantryUniqueConstraint1760033134668,
AllergyFriendlyToBoolType1763963056712,
UpdatePantryUserFieldsFixed1764350314832,
RemoveMultipleVolunteerTypes1764811878152,
RemoveUnusedStatuses1764816885341,
PopulateDummyData1768501812134,
RemovePantryFromOrders1769316004958,
],
migrations: [...schemaMigrations],
};

export default registerAs('typeorm', () => config);
Expand Down
36 changes: 36 additions & 0 deletions apps/backend/src/config/typeormTestDataSource.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on your note about needing to manually keep type.orm synced with typeormTestDataSource.ts - i'm considering an implementation where there is one shared migrations list that both files can import as a single source of truth.

idea is to define schema migrations once (ex. schemaMigrations) then:

  • in typeorm.ts: import schemaMigrations and createDummyData (plus future data seeding migrations if needed) to use in the config
  • in tests (ex. order.service.spec.ts): import schemaMigrations only as they are already written to run createDummyData before each test case

when new migrations are made, they can just be added to the schemaMigrations list

thoughts? this might be a bigger refactor for more of a tedious problem but worth to consider

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I ended up abstracting the migrations into one file so that we only need to update it there. I think we definitely still need 2 files though due to separate configurations. Take a look and make sure it runs for you and lmk.

NOTE: I think createDummyData is the wrong migration. When we merged the createDummyData pr in, I think we created a new migration, populateDummyData. This is now the one I have incorporated into all migrations, and I believe createDummyData is deprecated.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'dotenv/config';
import { DataSource, DataSourceOptions } from 'typeorm';
import { PluralNamingStrategy } from '../strategies/plural-naming.strategy';
import { Order } from '../orders/order.entity';
import { Pantry } from '../pantries/pantries.entity';
import { User } from '../users/user.entity';
import { Donation } from '../donations/donations.entity';
import { FoodManufacturer } from '../foodManufacturers/manufacturer.entity';
import { FoodRequest } from '../foodRequests/request.entity';
import { DonationItem } from '../donationItems/donationItems.entity';
import { Allocation } from '../allocations/allocations.entity';
import schemaMigrations from './migrations';

const testConfig: DataSourceOptions = {
type: 'postgres',
host: process.env.DATABASE_HOST ?? '127.0.0.1',
port: process.env.DATABASE_PORT ? parseInt(process.env.DATABASE_PORT) : 5432,
database: process.env.DATABASE_NAME_TEST ?? 'securing-safe-food-test',
username: process.env.DATABASE_USERNAME ?? 'postgres',
password: process.env.DATABASE_PASSWORD ?? 'postgres',
synchronize: false,
namingStrategy: new PluralNamingStrategy(),
entities: [
Order,
Pantry,
User,
Donation,
FoodManufacturer,
FoodRequest,
DonationItem,
Allocation,
],
migrations: schemaMigrations,
};

export const testDataSource = new DataSource(testConfig);
Loading