1
1
import { http , HttpResponse , delay } from "msw" ;
2
2
import {
3
3
Crystal ,
4
+ CrystalInput ,
4
5
HPCCluster ,
5
6
Molecule ,
6
7
MoleculeInput ,
@@ -9,34 +10,85 @@ import {
9
10
Person ,
10
11
Simulation ,
11
12
SimulationPage ,
13
+ Structure ,
14
+ StructureWithMetadata ,
15
+ XASData ,
12
16
} from "../models" ;
17
+ import { Cluster } from "cluster" ;
13
18
14
19
const orcaMockOutput = "********\n**ORCA RESULT**\n********" ;
20
+ const orcaMockJobfile = "********\n**ORCA JOBFILE**\n********" ;
15
21
16
- const mockMolecule : Molecule = {
22
+ const mockCrystalStructure : Crystal = {
17
23
id : 1 ,
18
- label : "MockBenzene" ,
19
-
20
- structure :
21
- "C 0.000000 1.402720 0.000000\nH 0.000000 2.490290 0.000000\nC -1.214790 0.701360 0.000000\nH -2.156660 1.245150 0.000000\nC -1.214790 -0.701360 0.000000\nH -2.156660 -1.245150 0.000000\nC 0.000000 -1.402720 0.000000\nH 0.000000 -2.490290 0.000000\nC 1.214790 -0.701360 0.000000\nH 2.156660 -1.245150 0.000000\nC 1.214790 0.701360 0.000000\nH 2.156660 1.245150 0.000000" ,
24
+ lattice : {
25
+ a : 4.1043564 ,
26
+ b : 4.1043564 ,
27
+ c : 4.1043564 ,
28
+ alpha : 90 ,
29
+ beta : 90 ,
30
+ gamma : 90 ,
31
+ } ,
32
+ label : "test" ,
33
+ sites : [
34
+ { element_z : 47 , x : 0.0 , y : 0.0 , z : 0.0 , index : 1 } ,
35
+ { element_z : 47 , x : 0.5 , y : 0.5 , z : 0.0 , index : 2 } ,
36
+ { element_z : 47 , x : 0.5 , y : 0.0 , z : 0.5 , index : 3 } ,
37
+ { element_z : 47 , x : 0.0 , y : 0.5 , z : 0.5 , index : 4 } ,
38
+ ] ,
22
39
} ;
23
40
24
- const mockCrystal : Crystal = {
41
+ const mockCrystal : Structure = {
25
42
id : 1 ,
43
+ label : "test" ,
44
+ person_id : 1 ,
45
+ lattice_id : 1 ,
46
+ } ;
47
+
48
+ const mockCrysWithMetadata : StructureWithMetadata = {
49
+ atom_count : 4 ,
50
+ elements : [ 47 ] ,
51
+ structure : mockCrystal ,
52
+ } ;
26
53
27
- a : 4.1043564 ,
28
- b : 4.1043564 ,
29
- c : 4.1043564 ,
30
- alpha : 90 ,
31
- beta : 90 ,
32
- gamma : 90 ,
54
+ const mockMoleculeStructure : Molecule = {
55
+ id : 2 ,
56
+ label : "Benzene" ,
57
+ sites : [
58
+ { index : 1 , element_z : 6 , x : 0.0 , y : 1.40272 , z : 0.0 } ,
59
+ { index : 2 , element_z : 1 , x : 0.0 , y : 2.49029 , z : 0.0 } ,
60
+ { index : 3 , element_z : 6 , x : - 1.21479 , y : 0.70136 , z : 0.0 } ,
61
+ { index : 4 , element_z : 1 , x : - 2.15666 , y : 1.24515 , z : 0.0 } ,
62
+ { index : 5 , element_z : 6 , x : - 1.21479 , y : - 0.70136 , z : 0.0 } ,
63
+ { index : 6 , element_z : 1 , x : - 2.15666 , y : - 1.24515 , z : 0.0 } ,
64
+ { index : 7 , element_z : 6 , x : 0.0 , y : - 1.40272 , z : 0.0 } ,
65
+ { index : 8 , element_z : 1 , x : 0.0 , y : - 2.49029 , z : 0.0 } ,
66
+ { index : 9 , element_z : 6 , x : 1.21479 , y : - 0.70136 , z : 0.0 } ,
67
+ { index : 10 , element_z : 1 , x : 2.15666 , y : - 1.24515 , z : 0.0 } ,
68
+ { index : 11 , element_z : 6 , x : 1.21479 , y : 0.70136 , z : 0.0 } ,
69
+ { index : 12 , element_z : 1 , x : 2.15666 , y : 1.24515 , z : 0.0 } ,
70
+ ] ,
71
+ } ;
72
+
73
+ const mockMole : Structure = {
74
+ id : 2 ,
33
75
label : "test" ,
34
- structure : "Ag 0. 0. 0.\nAg 0.5 0.5 0.\nAg 0.5 0. 0.5\nAg 0. 0.5 0.5" ,
76
+ person_id : 1 ,
77
+ lattice_id : null ,
35
78
} ;
36
79
37
- const mockCrystalArray = [ mockCrystal ] ;
80
+ const mockMoleWithMetadata : StructureWithMetadata = {
81
+ atom_count : 12 ,
82
+ elements : [ 1 , 6 ] ,
83
+ structure : mockMole ,
84
+ } ;
38
85
39
- const mockArray = [ mockMolecule ] ;
86
+ const mockXASdata : XASData = {
87
+ energy : [ 1 , 2 , 3 , 4 , 5 ] ,
88
+ xas : [ 1 , 2 , 3 , 2 , 1 ] ,
89
+ stk_energy : [ 2 , 3 , 3 , 3 , 4 ] ,
90
+ stk_xas : [ 0 , 0 , 3 , 0 , 0 ] ,
91
+ } ;
40
92
41
93
const mockSimulation : Simulation = {
42
94
id : 1 ,
@@ -46,7 +98,7 @@ const mockSimulation: Simulation = {
46
98
status : "mock" ,
47
99
working_directory : "/mock" ,
48
100
request_date : "2025-02-27T09:22:41.035872" ,
49
- chemical_structure_id : 1 ,
101
+ chemical_structure_id : 2 ,
50
102
submission_date : null ,
51
103
completion_date : null ,
52
104
} ;
@@ -69,34 +121,6 @@ const mockOrcaSimulation: OrcaSimulation = {
69
121
const mockSimulations = [ mockSimulation ] ;
70
122
71
123
export const handlers = [
72
- http . get ( "/api/molecules" , async ( ) => {
73
- await delay ( 10000 ) ;
74
- return HttpResponse . json ( mockArray ) ;
75
- } ) ,
76
-
77
- http . get ( "/api/molecules/:id" , ( { params } ) => {
78
- const { id } = params ;
79
-
80
- const mol = mockArray . find ( ( el ) => el . id == Number ( id ) ) ;
81
-
82
- if ( mol ) {
83
- return HttpResponse . json ( mol ) ;
84
- } else {
85
- return new HttpResponse ( null , { status : 404 } ) ;
86
- }
87
- } ) ,
88
-
89
- http . post ( "/api/molecules" , async ( { request } ) => {
90
- // Read the intercepted request body as JSON.
91
- const newMolecule = ( await request . json ( ) ) as MoleculeInput ;
92
-
93
- const responseMolecule : Molecule = { ...newMolecule , id : 10 } ;
94
-
95
- // Don't forget to declare a semantic "201 Created"
96
- // response and send back the newly created post!
97
- return HttpResponse . json ( responseMolecule , { status : 201 } ) ;
98
- } ) ,
99
-
100
124
http . get ( "/api/simulations" , ( ) => {
101
125
const page : SimulationPage = {
102
126
items : [ mockSimulation ] ,
@@ -128,12 +152,18 @@ export const handlers = [
128
152
return HttpResponse . json ( mockOrcaSimulation ) ;
129
153
} ) ,
130
154
131
- http . get ( "/api/orca/:id/output" , ( { params } ) => {
132
- const { id } = params ;
133
-
155
+ http . get ( "/api/orca/:id/output" , ( ) => {
134
156
return HttpResponse . text ( orcaMockOutput ) ;
135
157
} ) ,
136
158
159
+ http . get ( "/api/orca/:id/jobfile" , ( ) => {
160
+ return HttpResponse . text ( orcaMockJobfile ) ;
161
+ } ) ,
162
+
163
+ http . get ( "/api/orca/:id/xas" , ( ) => {
164
+ return HttpResponse . json ( mockXASdata ) ;
165
+ } ) ,
166
+
137
167
http . post ( "/api/submit/orca" , async ( { request } ) => {
138
168
// Read the intercepted request body as JSON.
139
169
const newOrcaSimulation = ( await request . json ( ) ) as OrcaSimulationInput ;
@@ -148,38 +178,71 @@ export const handlers = [
148
178
return HttpResponse . json ( responseSimulation , { status : 201 } ) ;
149
179
} ) ,
150
180
151
- http . get ( "/api/crystals" , async ( ) => {
152
- return HttpResponse . json ( mockCrystalArray ) ;
153
- } ) ,
154
-
155
181
http . get ( "/api/user" , async ( request ) => {
156
182
const auth = request . request . headers . get ( "authorization" ) ;
157
183
158
184
if ( auth && auth . startsWith ( "Bearer " ) ) {
159
- const user : Person = { identifier : auth . slice ( 7 ) } ;
185
+ const user : Person = {
186
+ identifier : auth . slice ( 7 ) ,
187
+ accepted_orca_eula : true ,
188
+ } ;
160
189
return HttpResponse . json ( user ) ;
161
190
}
162
191
163
192
return new HttpResponse ( null , { status : 401 } ) ;
164
193
} ) ,
165
194
195
+ http . get ( "/api/cluster/status" , async ( ) => {
196
+ const clusterStatus : HPCCluster = {
197
+ id : 1 ,
198
+ updated : new Date ( Date . now ( ) ) . toISOString ( ) . slice ( 0 , - 1 ) ,
199
+ } ;
200
+ return HttpResponse . json ( clusterStatus ) ;
201
+ } ) ,
202
+
166
203
http . get ( "/api/matproj/:id" , async ( request ) => {
167
204
const auth = request . request . headers . get ( "authorization" ) ;
168
205
169
206
if ( auth && auth . startsWith ( "Bearer " ) ) {
170
- return HttpResponse . json ( mockCrystal ) ;
207
+ return HttpResponse . json ( mockCrystalStructure ) ;
171
208
}
172
209
173
210
return new HttpResponse ( null , { status : 401 } ) ;
174
211
} ) ,
175
212
176
213
http . get ( "/api/cluster/status" , async ( ) => {
214
+ const cluster : HPCCluster = { id : 1 , updated : Date . now ( ) . toString ( ) } ;
177
215
216
+ return HttpResponse . json ( cluster ) ;
217
+ } ) ,
178
218
179
- const cluster : HPCCluster = { id : 1 , updated : Date . now ( ) . toString ( ) }
219
+ http . get ( "/api/structures" , async ( { request } ) => {
220
+ const url = new URL ( request . url ) ;
180
221
222
+ console . log ( url ) ;
181
223
224
+ // Given a request url of "/product?id=1",
225
+ // the `productId` will be a "1" string.
226
+ const type = url . searchParams . get ( "type" ) ;
227
+
228
+ console . log ( type ) ;
229
+
230
+ if ( type == "crystal" ) {
231
+ return HttpResponse . json ( [ mockCrysWithMetadata ] ) ;
232
+ } else {
233
+ return HttpResponse . json ( [ mockMoleWithMetadata ] ) ;
234
+ }
235
+ } ) ,
236
+
237
+ http . get ( "/api/structures/:id" , async ( { params } ) => {
238
+ const { id } = params ;
239
+
240
+ if ( id == "1" ) {
241
+ return HttpResponse . json ( mockCrystalStructure ) ;
242
+ } else if ( id == "2" ) {
243
+ return HttpResponse . json ( mockMoleculeStructure ) ;
244
+ }
182
245
183
- return HttpResponse . json ( cluster )
246
+ return new HttpResponse ( null , { status : 404 } ) ;
184
247
} ) ,
185
248
] ;
0 commit comments