Skip to content

Commit 227ae38

Browse files
Add test and tie breaker for sort
1 parent f03b39d commit 227ae38

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

integration_tests/environments.lua

+65
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,68 @@ Test.gql("workloads in environment", function(t)
228228
},
229229
}
230230
end)
231+
232+
Test.gql("workloads in environment with custom order", function(t)
233+
t.addHeader("x-user-email", user:email())
234+
235+
t.query([[
236+
{
237+
environment(name: "dev") {
238+
workloads(
239+
orderBy: {
240+
field: TEAM_SLUG,
241+
direction: DESC
242+
}
243+
) {
244+
nodes {
245+
name
246+
team {
247+
slug
248+
}
249+
}
250+
}
251+
}
252+
}
253+
]])
254+
255+
t.check {
256+
data = {
257+
environment = {
258+
workloads = {
259+
nodes = {
260+
{
261+
name = "app-name",
262+
team = {
263+
slug = "slug-2",
264+
},
265+
},
266+
{
267+
name = "another-app",
268+
team = {
269+
slug = "slug-1",
270+
},
271+
},
272+
{
273+
name = "app-name",
274+
team = {
275+
slug = "slug-1",
276+
},
277+
},
278+
{
279+
name = "jobname-1",
280+
team = {
281+
slug = "slug-1",
282+
},
283+
},
284+
{
285+
name = "jobname-2",
286+
team = {
287+
slug = "slug-1",
288+
},
289+
},
290+
},
291+
},
292+
},
293+
},
294+
}
295+
end)

internal/workload/sortfilter.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ func init() {
4747
Direction: ptr.To(model.OrderDirectionAsc),
4848
},
4949
)
50-
SortFilterEnvironment.RegisterSort("TEAM_SLUG", func(ctx context.Context, a, b Workload) int {
51-
return strings.Compare(a.GetTeamSlug().String(), b.GetTeamSlug().String())
52-
})
50+
SortFilterEnvironment.RegisterSort(
51+
"TEAM_SLUG",
52+
func(ctx context.Context, a, b Workload) int {
53+
return strings.Compare(a.GetTeamSlug().String(), b.GetTeamSlug().String())
54+
},
55+
SortFilterEnvironmentTieBreaker{
56+
Field: "NAME",
57+
Direction: ptr.To(model.OrderDirectionAsc),
58+
},
59+
)
5360
}

0 commit comments

Comments
 (0)