Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor AMFlowClient #13

Merged
merged 3 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 94 additions & 4 deletions packages/headless-driver/src/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as url from "url";
import fetch from "node-fetch";

import { Permission, StartPoint, GetStartPointOptions } from "@akashic/amflow";
import { Event } from "@akashic/playlog";
import { RunnerV1, RunnerV1Game } from "@akashic/headless-driver-runner-v1";
import { RunnerV2, RunnerV2Game } from "@akashic/headless-driver-runner-v2";

Expand Down Expand Up @@ -248,6 +249,7 @@ describe("run-test", () => {
if (err) {
assert.equal(err instanceof Error, true);
assert.equal(permission == null, true);
assert.strictEqual(err.name, "InvalidStatus");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主変更 2. のテストです。

resolve();
return;
}
Expand Down Expand Up @@ -297,10 +299,6 @@ describe("run-test", () => {
});
});
})
.then(() => {
activeAMFlow.open(playId);
passiveAMFlow.open(playId);
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上ですでに open していたので無駄な呼び出しでした。

.then(() => {
return new Promise((resolve, reject) => {
// Tick を送信できる
Expand Down Expand Up @@ -333,6 +331,13 @@ describe("run-test", () => {
passiveAMFlow.sendEvent([0, 5, "dummy-player-id"]);
});
})
.then(() => playManager.stopPlay(playId))
.then(() => {
return new Promise((resolve, reject) => {
// すでに stop したプレーの AMFlowClient に対して close() を呼び出しても問題ない
passiveAMFlow.close(err => (err ? reject(err) : resolve()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主変更 3. のテストです。

});
})
.then(done)
.catch(e => done(e));
});
Expand Down Expand Up @@ -422,6 +427,91 @@ describe("AMFlow の動作テスト", () => {
});
});
});

it("AMFlow#onEvent が登録されるより以前の Event を正しく取得できる", done => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主変更 1. のテストです。

const playManager = new PlayManager();
let activeAMFlow: AMFlowClient;
let passiveAMFlow: AMFlowClient;
const playId = "0";
const events: Event[] = [];

Promise.resolve()
.then(() => {
return new Promise((resolve, reject) => {
activeAMFlow = playManager.createAMFlow(playId);
activeAMFlow.open(playId, err => {
if (err) {
reject(err);
return;
}
resolve();
});
});
})
.then(() => {
return new Promise((resolve, reject) => {
passiveAMFlow = playManager.createAMFlow(playId);
passiveAMFlow.open(playId, err => {
if (err) {
reject(err);
return;
}
resolve();
});
});
})
.then(() => {
return new Promise((resolve, reject) => {
// 認証できる
const playToken = playManager.createPlayToken(playId, passivePermission);
passiveAMFlow.authenticate(playToken, err => {
if (err) {
reject(err);
return;
}
resolve();
});
});
})
.then(() => {
// active の AMFlow#authenticate(), AMFlow#onEvent() 呼び出し前にイベントを送信
passiveAMFlow.sendEvent([0x20, 0, null, { ordinal: 1, hoge: "fuga" }]);
passiveAMFlow.sendEvent([0x20, 0, null, { ordinal: 2, foo: "bar" }]);
})
.then(() => {
return new Promise((resolve, reject) => {
// Active の認証
const playToken = playManager.createPlayToken(playId, activePermission);
activeAMFlow.authenticate(playToken, err => {
if (err) {
reject(err);
return;
}
resolve();
});
});
})
.then(() => {
activeAMFlow.onEvent(event => {
events.push(event);
});
})
.then(() => {
// active の AMFlow#onEvent() 呼び出し後にイベントを送信
passiveAMFlow.sendEvent([0x20, 0, null, { ordinal: 3 }]);
passiveAMFlow.sendEvent([0x20, 0, null, { ordinal: 4 }]);
})
.then(() => {
assert.deepStrictEqual(events, [
[0x20, 0, null, { ordinal: 1, hoge: "fuga" }],
[0x20, 0, null, { ordinal: 2, foo: "bar" }],
[0x20, 0, null, { ordinal: 3 }],
[0x20, 0, null, { ordinal: 4 }]
]);
})
.then(done)
.catch(e => done(e));
});
});

describe("コンテンツ動作テスト", () => {
Expand Down
Loading