Skip to content

Commit 8e85ce8

Browse files
committed
Test case
1 parent 7b25f96 commit 8e85ce8

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
2+
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause
3+
4+
package lucuma.odb.graphql.subscription
5+
6+
import cats.effect.IO
7+
import cats.syntax.show.*
8+
import io.circe.Json
9+
import io.circe.syntax.*
10+
import lucuma.core.model.Observation
11+
import lucuma.core.model.Program
12+
import lucuma.odb.data.EditType
13+
import lucuma.odb.graphql.query.ExecutionTestSupport
14+
import lucuma.odb.graphql.query.ObservingModeSetupOperations
15+
16+
class observationEditSn extends ExecutionTestSupport with ObservingModeSetupOperations with SubscriptionUtils:
17+
18+
def subscriptionQuery(pid: Program.Id) =
19+
s"""
20+
subscription {
21+
observationEdit(input: { programId: "${pid.show}" }) {
22+
observationId
23+
editType
24+
value {
25+
id
26+
execution {
27+
config {
28+
gmosNorth {
29+
science {
30+
nextAtom {
31+
observeClass
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
40+
"""
41+
42+
def subscriptionResponse(oid: Observation.Id): Json =
43+
Json.obj(
44+
"observationEdit" -> Json.obj(
45+
"observationId" -> Json.fromString(oid.show),
46+
"editType" -> Json.fromString(EditType.Updated.tag.toUpperCase),
47+
"value" -> Json.obj(
48+
"id" -> oid.asJson,
49+
"execution" -> Json.obj(
50+
"config" -> Json.obj(
51+
"gmosNorth" -> Json.obj(
52+
"science" -> Json.obj(
53+
"nextAtom" -> Json.obj(
54+
"observeClass" -> "SCIENCE".asJson
55+
)
56+
)
57+
)
58+
)
59+
)
60+
)
61+
)
62+
)
63+
64+
def updateSn(
65+
oid: Observation.Id
66+
): IO[Unit] =
67+
query(
68+
user = pi,
69+
query = s"""
70+
mutation {
71+
updateObservations(input: {
72+
SET: {
73+
scienceRequirements: {
74+
spectroscopy: {
75+
exposureTimeMode: {
76+
signalToNoise: {
77+
value: 99
78+
at: { nanometers: 500 }
79+
}
80+
}
81+
}
82+
}
83+
},
84+
WHERE: {
85+
id: { EQ: "$oid" }
86+
}
87+
}) {
88+
observations {
89+
scienceRequirements {
90+
spectroscopy {
91+
exposureTimeMode {
92+
signalToNoise {
93+
value
94+
}
95+
}
96+
}
97+
}
98+
}
99+
}
100+
}
101+
"""
102+
).void
103+
104+
test("triggers for editing s/n"):
105+
for
106+
pid <- createProgram(pi, "foo")
107+
tid <- createTargetWithProfileAs(pi, pid)
108+
oid <- createGmosNorthLongSlitObservationAs(pi, pid, List(tid))
109+
_ <- generateOrFail(pid, oid)
110+
// expect two responses, one from editing the S/N, one because our query
111+
// requests the sequence which requires a cache update
112+
_ <- subscriptionExpect(
113+
user = pi,
114+
query = subscriptionQuery(pid),
115+
mutations = Right(sleep >> updateSn(oid)),
116+
expected = List(subscriptionResponse(oid), subscriptionResponse(oid))
117+
)
118+
yield ()
119+
120+
test("does not trigger for subsequent generation"):
121+
for
122+
pid <- createProgram(pi, "foo")
123+
tid <- createTargetWithProfileAs(pi, pid)
124+
oid <- createGmosNorthLongSlitObservationAs(pi, pid, List(tid))
125+
_ <- generateOrFail(pid, oid)
126+
_ <- subscriptionExpect(
127+
user = pi,
128+
query = subscriptionQuery(pid),
129+
mutations = Right(
130+
sleep >>
131+
updateSn(oid) >>
132+
generateOrFail(pid, oid).void >>
133+
generateOrFail(pid, oid).void >>
134+
sleep
135+
),
136+
expected = List(subscriptionResponse(oid), subscriptionResponse(oid))
137+
)
138+
yield ()

0 commit comments

Comments
 (0)