@gameye/sdk
Version:
Node.js SDK for Gameye
96 lines • 3.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const test = require("blue-tape");
const errors = require("../errors");
const test_1 = require("../test");
const utils_1 = require("../utils");
const gameye_1 = require("./gameye");
test("GameyeClient instantiation", async (t) => {
const client = new gameye_1.GameyeClient({
token: "123",
endpoint: "http://localhost",
});
});
test("GameyeClient config errors", async (t) => {
try {
const client = new gameye_1.GameyeClient({
endpoint: "http://localhost",
});
t.fail();
}
catch (err) {
if (err instanceof errors.MissingConfigurationField) {
t.equal(err.fieldName, "token");
err = null;
}
if (err)
throw err;
}
});
test("GameyeClient subscriptions", t => utils_1.use(test_1.TestContext.create(), async ({ gameyeClient, apiTestServer }) => {
const subscription = await gameyeClient.subscribe("testing", {});
apiTestServer.emitPatches([
{ path: ["number"], value: 1 },
]);
{
const state = await utils_1.streamWait(subscription);
t.deepEqual(state, { number: 1 });
}
apiTestServer.emitPatches([
{ path: ["number"], value: 2 },
]);
{
const state = await utils_1.streamWait(subscription);
t.deepEqual(state, { number: 2 });
}
apiTestServer.emitPatches([
{ path: ["character"], value: "a" },
]);
{
const state = await utils_1.streamWait(subscription);
t.deepEqual(state, { number: 2, character: "a" });
}
// it's very important to always cleanup a subscription!
subscription.destroy();
await utils_1.whenFinished(subscription);
}));
test("GameyeClient subscriptions async iterable", t => utils_1.use(test_1.TestContext.create(), async ({ gameyeClient, apiTestServer }) => {
var e_1, _a;
const subscription = await gameyeClient.subscribe("testing", {});
const patches = [
[{ path: ["number"], value: 1 }],
[{ path: ["number"], value: 2 }],
[{ path: ["character"], value: "a" }],
];
const expectedStates = [
{ number: 1 },
{ number: 2 },
{ number: 2, character: "a" },
];
let patch;
// tslint:disable-next-line: no-conditional-assignment
while (patch = patches.shift()) {
apiTestServer.emitPatches(patch);
}
try {
for (var subscription_1 = tslib_1.__asyncValues(subscription), subscription_1_1; subscription_1_1 = await subscription_1.next(), !subscription_1_1.done;) {
const state = subscription_1_1.value;
const expectedState = expectedStates.shift();
t.deepEqual(state, expectedState);
if (expectedStates.length === 0)
break;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (subscription_1_1 && !subscription_1_1.done && (_a = subscription_1.return)) await _a.call(subscription_1);
}
finally { if (e_1) throw e_1.error; }
}
// it's very important to always cleanup a subscription!
subscription.destroy();
await utils_1.whenFinished(subscription);
}));
//# sourceMappingURL=gameye.spec.js.map