@google-cloud/agones-sdk 1.55.0 → 1.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/biome.json +24 -0
- package/package.json +7 -7
- package/spec/agonesSDK.spec.js +481 -467
- package/spec/alphaAgonesSDK.spec.js +288 -254
- package/spec/betaAgonesSDK.spec.js +427 -419
- package/spec/support/jasmine.json +6 -8
- package/src/agonesSDK.d.ts +25 -22
- package/src/agonesSDK.js +13 -11
- package/src/alpha.d.ts +7 -7
- package/src/alpha.js +130 -130
- package/src/beta.d.ts +13 -13
- package/src/beta.js +248 -248
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/.eslintrc.json +0 -18
|
@@ -1,254 +1,288 @@
|
|
|
1
|
-
// Copyright 2020 Google LLC All Rights Reserved.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
const grpc = require(
|
|
16
|
-
|
|
17
|
-
const messages = require(
|
|
18
|
-
const Alpha = require(
|
|
19
|
-
|
|
20
|
-
describe(
|
|
21
|
-
let alpha;
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
const address =
|
|
25
|
-
const credentials = grpc.credentials.createInsecure();
|
|
26
|
-
alpha = new Alpha(address, credentials);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe(
|
|
30
|
-
it(
|
|
31
|
-
spyOn(alpha.client,
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
it(
|
|
215
|
-
spyOn(alpha.client,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
expect(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
1
|
+
// Copyright 2020 Google LLC All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
const grpc = require("@grpc/grpc-js");
|
|
16
|
+
|
|
17
|
+
const messages = require("../lib/alpha/alpha_pb");
|
|
18
|
+
const Alpha = require("../src/alpha");
|
|
19
|
+
|
|
20
|
+
describe("Alpha", () => {
|
|
21
|
+
let alpha;
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
const address = "localhost:9357";
|
|
25
|
+
const credentials = grpc.credentials.createInsecure();
|
|
26
|
+
alpha = new Alpha(address, credentials);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("playerConnect", () => {
|
|
30
|
+
it("calls the server and handles success when the player is not connected", async () => {
|
|
31
|
+
spyOn(alpha.client, "playerConnect").and.callFake(
|
|
32
|
+
(_request, callback) => {
|
|
33
|
+
const result = new messages.Bool();
|
|
34
|
+
result.setBool(true);
|
|
35
|
+
callback(undefined, result);
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const result = await alpha.playerConnect("playerID");
|
|
40
|
+
expect(alpha.client.playerConnect).toHaveBeenCalled();
|
|
41
|
+
expect(result).toEqual(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("calls the server and handles success when the player is already connected", async () => {
|
|
45
|
+
spyOn(alpha.client, "playerConnect").and.callFake(
|
|
46
|
+
(_request, callback) => {
|
|
47
|
+
const result = new messages.Bool();
|
|
48
|
+
result.setBool(false);
|
|
49
|
+
callback(undefined, result);
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const result = await alpha.playerConnect("playerID");
|
|
54
|
+
expect(alpha.client.playerConnect).toHaveBeenCalled();
|
|
55
|
+
expect(result).toEqual(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("calls the server and handles failure", async () => {
|
|
59
|
+
spyOn(alpha.client, "playerConnect").and.callFake(
|
|
60
|
+
(_request, callback) => {
|
|
61
|
+
callback("error", undefined);
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
try {
|
|
65
|
+
await alpha.playerConnect("playerID");
|
|
66
|
+
fail();
|
|
67
|
+
} catch (error) {
|
|
68
|
+
expect(alpha.client.playerConnect).toHaveBeenCalled();
|
|
69
|
+
expect(error).toEqual("error");
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("playerDisconnect", () => {
|
|
75
|
+
it("calls the server and handles success when the player is connected", async () => {
|
|
76
|
+
spyOn(alpha.client, "playerDisconnect").and.callFake(
|
|
77
|
+
(_request, callback) => {
|
|
78
|
+
const result = new messages.Bool();
|
|
79
|
+
result.setBool(true);
|
|
80
|
+
callback(undefined, result);
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const result = await alpha.playerDisconnect("playerID");
|
|
85
|
+
expect(alpha.client.playerDisconnect).toHaveBeenCalled();
|
|
86
|
+
expect(result).toEqual(true);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("calls the server and handles success when the player is not connected", async () => {
|
|
90
|
+
spyOn(alpha.client, "playerDisconnect").and.callFake(
|
|
91
|
+
(_request, callback) => {
|
|
92
|
+
const result = new messages.Bool();
|
|
93
|
+
result.setBool(false);
|
|
94
|
+
callback(undefined, result);
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const result = await alpha.playerDisconnect("playerID");
|
|
99
|
+
expect(alpha.client.playerDisconnect).toHaveBeenCalled();
|
|
100
|
+
expect(result).toEqual(false);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("calls the server and handles failure", async () => {
|
|
104
|
+
spyOn(alpha.client, "playerDisconnect").and.callFake(
|
|
105
|
+
(_request, callback) => {
|
|
106
|
+
callback("error", undefined);
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
try {
|
|
110
|
+
await alpha.playerDisconnect("playerID");
|
|
111
|
+
fail();
|
|
112
|
+
} catch (error) {
|
|
113
|
+
expect(alpha.client.playerDisconnect).toHaveBeenCalled();
|
|
114
|
+
expect(error).toEqual("error");
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe("setPlayerCapacity", () => {
|
|
120
|
+
it("passes arguments to the server and handles success", async () => {
|
|
121
|
+
spyOn(alpha.client, "setPlayerCapacity").and.callFake(
|
|
122
|
+
(_request, callback) => {
|
|
123
|
+
const result = new messages.Empty();
|
|
124
|
+
callback(undefined, result);
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const result = await alpha.setPlayerCapacity(64);
|
|
129
|
+
expect(result).toEqual({});
|
|
130
|
+
expect(alpha.client.setPlayerCapacity).toHaveBeenCalled();
|
|
131
|
+
const request = alpha.client.setPlayerCapacity.calls.argsFor(0)[0];
|
|
132
|
+
expect(request.getCount()).toEqual(64);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("calls the server and handles failure", async () => {
|
|
136
|
+
spyOn(alpha.client, "setPlayerCapacity").and.callFake(
|
|
137
|
+
(_request, callback) => {
|
|
138
|
+
callback("error", undefined);
|
|
139
|
+
},
|
|
140
|
+
);
|
|
141
|
+
try {
|
|
142
|
+
await alpha.setPlayerCapacity(64);
|
|
143
|
+
fail();
|
|
144
|
+
} catch (error) {
|
|
145
|
+
expect(alpha.client.setPlayerCapacity).toHaveBeenCalled();
|
|
146
|
+
expect(error).toEqual("error");
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("getPlayerCapacity", () => {
|
|
152
|
+
it("calls the server and handles the response", async () => {
|
|
153
|
+
spyOn(alpha.client, "getPlayerCapacity").and.callFake(
|
|
154
|
+
(_request, callback) => {
|
|
155
|
+
const capacity = new messages.Count();
|
|
156
|
+
capacity.setCount(64);
|
|
157
|
+
callback(undefined, capacity);
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const capacity = await alpha.getPlayerCapacity();
|
|
162
|
+
expect(alpha.client.getPlayerCapacity).toHaveBeenCalled();
|
|
163
|
+
expect(capacity).toEqual(64);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("calls the server and handles failure", async () => {
|
|
167
|
+
spyOn(alpha.client, "getPlayerCapacity").and.callFake(
|
|
168
|
+
(_request, callback) => {
|
|
169
|
+
callback("error", undefined);
|
|
170
|
+
},
|
|
171
|
+
);
|
|
172
|
+
try {
|
|
173
|
+
await alpha.getPlayerCapacity();
|
|
174
|
+
fail();
|
|
175
|
+
} catch (error) {
|
|
176
|
+
expect(alpha.client.getPlayerCapacity).toHaveBeenCalled();
|
|
177
|
+
expect(error).toEqual("error");
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe("getPlayerCount", () => {
|
|
183
|
+
it("calls the server and handles the response", async () => {
|
|
184
|
+
spyOn(alpha.client, "getPlayerCount").and.callFake(
|
|
185
|
+
(_request, callback) => {
|
|
186
|
+
const capacity = new messages.Count();
|
|
187
|
+
capacity.setCount(16);
|
|
188
|
+
callback(undefined, capacity);
|
|
189
|
+
},
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
const capacity = await alpha.getPlayerCount();
|
|
193
|
+
expect(alpha.client.getPlayerCount).toHaveBeenCalled();
|
|
194
|
+
expect(capacity).toEqual(16);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("calls the server and handles failure", async () => {
|
|
198
|
+
spyOn(alpha.client, "getPlayerCount").and.callFake(
|
|
199
|
+
(_request, callback) => {
|
|
200
|
+
callback("error", undefined);
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
try {
|
|
204
|
+
await alpha.getPlayerCount();
|
|
205
|
+
fail();
|
|
206
|
+
} catch (error) {
|
|
207
|
+
expect(alpha.client.getPlayerCount).toHaveBeenCalled();
|
|
208
|
+
expect(error).toEqual("error");
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
describe("isPlayerConnected", () => {
|
|
214
|
+
it("calls the server and handles success when the player is connected", async () => {
|
|
215
|
+
spyOn(alpha.client, "isPlayerConnected").and.callFake(
|
|
216
|
+
(_request, callback) => {
|
|
217
|
+
const result = new messages.Bool();
|
|
218
|
+
result.setBool(true);
|
|
219
|
+
callback(undefined, result);
|
|
220
|
+
},
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
const result = await alpha.isPlayerConnected("playerID");
|
|
224
|
+
expect(alpha.client.isPlayerConnected).toHaveBeenCalled();
|
|
225
|
+
expect(result).toEqual(true);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("calls the server and handles success when the player is not connected", async () => {
|
|
229
|
+
spyOn(alpha.client, "isPlayerConnected").and.callFake(
|
|
230
|
+
(_request, callback) => {
|
|
231
|
+
const result = new messages.Bool();
|
|
232
|
+
result.setBool(false);
|
|
233
|
+
callback(undefined, result);
|
|
234
|
+
},
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const result = await alpha.isPlayerConnected("playerID");
|
|
238
|
+
expect(alpha.client.isPlayerConnected).toHaveBeenCalled();
|
|
239
|
+
expect(result).toEqual(false);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("calls the server and handles failure", async () => {
|
|
243
|
+
spyOn(alpha.client, "isPlayerConnected").and.callFake(
|
|
244
|
+
(_request, callback) => {
|
|
245
|
+
callback("error", undefined);
|
|
246
|
+
},
|
|
247
|
+
);
|
|
248
|
+
try {
|
|
249
|
+
await alpha.isPlayerConnected("playerID");
|
|
250
|
+
fail();
|
|
251
|
+
} catch (error) {
|
|
252
|
+
expect(alpha.client.isPlayerConnected).toHaveBeenCalled();
|
|
253
|
+
expect(error).toEqual("error");
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe("getConnectedPlayers", () => {
|
|
259
|
+
it("calls the server and handles the response", async () => {
|
|
260
|
+
spyOn(alpha.client, "getConnectedPlayers").and.callFake(
|
|
261
|
+
(_request, callback) => {
|
|
262
|
+
const connectedPlayers = new messages.PlayerIDList();
|
|
263
|
+
connectedPlayers.setListList(["firstPlayerID", "secondPlayerID"]);
|
|
264
|
+
callback(undefined, connectedPlayers);
|
|
265
|
+
},
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
const connectedPlayers = await alpha.getConnectedPlayers();
|
|
269
|
+
expect(alpha.client.getConnectedPlayers).toHaveBeenCalled();
|
|
270
|
+
expect(connectedPlayers).toEqual(["firstPlayerID", "secondPlayerID"]);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("calls the server and handles failure", async () => {
|
|
274
|
+
spyOn(alpha.client, "getConnectedPlayers").and.callFake(
|
|
275
|
+
(_request, callback) => {
|
|
276
|
+
callback("error", undefined);
|
|
277
|
+
},
|
|
278
|
+
);
|
|
279
|
+
try {
|
|
280
|
+
await alpha.getConnectedPlayers();
|
|
281
|
+
fail();
|
|
282
|
+
} catch (error) {
|
|
283
|
+
expect(alpha.client.getConnectedPlayers).toHaveBeenCalled();
|
|
284
|
+
expect(error).toEqual("error");
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|