better end points and better tests
This commit is contained in:
@@ -131,3 +131,38 @@ func DecodeJSON(t *testing.T, w *httptest.ResponseRecorder, dst any) {
|
||||
t.Fatalf("DecodeJSON: %v\n\tbody: %s", err, w.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
// SeedFixtures inserts one department and one GL account into db and returns
|
||||
// their IDs. Call this at the top of any test that needs FK-valid actuals or
|
||||
// budget rows.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// deptID, glID := testutil.SeedFixtures(t, db)
|
||||
func SeedFixtures(t *testing.T, db *sql.DB) (deptID int, glAccountID int) {
|
||||
t.Helper()
|
||||
|
||||
res, err := db.Exec(`
|
||||
INSERT INTO departments (code, name, cost_center, active)
|
||||
VALUES ('TEST', 'Test Department', 'CC-TEST', 1)
|
||||
ON CONFLICT(code) DO UPDATE SET name = excluded.name
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatalf("SeedFixtures: insert department: %v", err)
|
||||
}
|
||||
id, _ := res.LastInsertId()
|
||||
deptID = int(id)
|
||||
|
||||
res, err = db.Exec(`
|
||||
INSERT INTO gl_accounts (code, description, type, favour_high, active)
|
||||
VALUES ('TEST', 'Test Revenue', 'revenue', 1, 1)
|
||||
ON CONFLICT(code) DO UPDATE SET description = excluded.description
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatalf("SeedFixtures: insert gl_account: %v", err)
|
||||
}
|
||||
id, _ = res.LastInsertId()
|
||||
glAccountID = int(id)
|
||||
|
||||
return deptID, glAccountID
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user