FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
api/test/factory.go at main · Maroon-Rides/api · GitHub
Maroon-Rides
api
Repository navigation
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
api
/
test
/
factory.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
100 lines (88 loc) · 2.67 KB
Breadcrumbs
api
/
test
/
factory.go
Copy path
File metadata and controls
100 lines (88 loc) · 2.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package
test
import
(
"context"
"time"
"github.com/google/uuid"
.
"github.com/onsi/gomega"
"github.com/uptrace/bun"
"github.com/MaroonRides/api/internal/db/model"
)
// Network is one route with every synced table below it filled in.
type
Network
struct
{
Route
model.
Route
Direction
model.
Direction
Stop
model.
Stop
Alert
model.
Alert
AlertDirection
model.
AlertDirection
Timetable
model.
Timetable
}
// CreateNetwork fills every synced table. The name keeps unique columns apart across calls.
func
CreateNetwork
(
bundb
*
bun.
DB
,
name
string
)
Network
{
n
:=
Network
{
Route
: model.
Route
{
SourceID
:
"route-"
+
name
,
ShortName
:
name
,
LongName
:
"Route "
+
name
,
LightColor
:
"#500000"
,
DarkColor
:
"#ffffff"
,
Active
:
true
,
},
Alert
: model.
Alert
{
SourceID
:
"alert-"
+
name
,
Title
:
"Detour "
+
name
,
Description
:
"Construction"
,
TimeRangeText
:
"All day"
,
DailyStartTime
:
"00:00"
,
DailyEndTime
:
"23:59"
,
StartsAt
:
time
.
Date
(
2026
,
9
,
1
,
0
,
0
,
0
,
0
,
time
.
UTC
),
},
}
Insert
(
bundb
,
&
n
.
Route
)
Insert
(
bundb
,
&
n
.
Alert
)
n
.
Direction
=
model.
Direction
{
RouteID
:
n
.
Route
.
ID
,
SourceID
:
"direction-"
+
name
,
Destination
:
"Downtown"
,
Sequence
:
1
,
Path
:
"_p~iF~ps|U_ulLnnqC"
,
}
Insert
(
bundb
,
&
n
.
Direction
)
n
.
Stop
=
model.
Stop
{
DirectionID
:
n
.
Direction
.
ID
,
SourceID
:
"stop-"
+
name
,
Name
:
"Stop "
+
name
,
Lat
:
30.6187
,
Lon
:
-
96.3365
,
Amenities
: []
string
{
"shelter"
},
Sequence
:
1
,
IsTimepoint
:
true
,
}
Insert
(
bundb
,
&
n
.
Stop
)
n
.
AlertDirection
=
model.
AlertDirection
{
AlertID
:
n
.
Alert
.
ID
,
DirectionID
:
n
.
Direction
.
ID
}
n
.
Timetable
=
model.
Timetable
{
StopID
:
n
.
Stop
.
ID
,
ServiceDate
:
time
.
Date
(
2026
,
9
,
27
,
0
,
0
,
0
,
0
,
time
.
UTC
),
Departures
: []time.
Time
{
time
.
Date
(
2026
,
9
,
27
,
14
,
30
,
0
,
0
,
time
.
UTC
),
time
.
Date
(
2026
,
9
,
27
,
14
,
45
,
0
,
0
,
time
.
UTC
),
},
}
Insert
(
bundb
,
&
n
.
AlertDirection
)
Insert
(
bundb
,
&
n
.
Timetable
)
return
n
}
func
Insert
[
M
any
](
bundb
*
bun.
DB
,
row
*
M
) {
_
,
err
:=
bundb
.
NewInsert
().
Model
(
row
).
Returning
(
"*"
).
Exec
(
context
.
Background
())
ExpectWithOffset
(
1
,
err
).
NotTo
(
HaveOccurred
())
}
func
Exec
(
bundb
*
bun.
DB
,
query
string
,
args
...
any
) {
_
,
err
:=
bundb
.
ExecContext
(
context
.
Background
(),
query
,
args
...
)
ExpectWithOffset
(
1
,
err
).
NotTo
(
HaveOccurred
())
}
// UUIDv7Ago mints a uuidv7 on the database clock as if it were minted `ago` in the past.
func
UUIDv7Ago
(
bundb
*
bun.
DB
,
ago
time.
Duration
) uuid.
UUID
{
var
id
uuid.
UUID
err
:=
bundb
.
NewRaw
(
"SELECT uuidv7(-make_interval(secs => ?))"
,
ago
.
Seconds
()).
Scan
(
context
.
Background
(),
&
id
)
ExpectWithOffset
(
1
,
err
).
NotTo
(
HaveOccurred
())
return
id
}
Back
|
FazBrowse Home
|
New Git URL