Skip to content

Commit

Permalink
fix(test): cover more meta commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jun 5, 2021
1 parent 418d843 commit 54d67bc
Showing 1 changed file with 94 additions and 24 deletions.
118 changes: 94 additions & 24 deletions test/service/state/TestLocalState.ts
Expand Up @@ -18,9 +18,14 @@ import {
EVENT_LOADER_SAVE,
EVENT_LOADER_WORLD,
EVENT_STATE_OUTPUT,
META_CREATE,
META_DEBUG,
META_GRAPH,
META_HELP,
META_QUIT,
META_VERBS,
META_WORLDS,
TEMPLATE_CHANCE,
VERB_WAIT,
} from '../../../src/util/constants';
import { StateEntityGenerator } from '../../../src/util/state/EntityGenerator';
import { getTestContainer } from '../../helper';
Expand Down Expand Up @@ -152,7 +157,14 @@ describe('local state service', () => {
world: TEST_WORLD,
});

await localState.doCreate(TEST_WORLD.meta.id, 1);
await localState.onCommand({
command: {
index: 1,
input: '',
target: TEST_WORLD.meta.id,
verb: META_CREATE,
},
});

const rooms = await localState.stepFind({
type: ROOM_TYPE,
Expand All @@ -163,7 +175,7 @@ describe('local state service', () => {
});

describe('debug command', () => {
it('should print world contents for debug', async () => {
it('should print debug with state', async () => {
const container = await getTestContainer(new CoreModule());
const localState = await container.create(LocalStateService);
await localState.start();
Expand All @@ -175,9 +187,16 @@ describe('local state service', () => {

await localState.doCreate(TEST_WORLD.meta.id, 1);
const pending = onceEvent<StateOutputEvent>(events, EVENT_STATE_OUTPUT);
await localState.doDebug();
const output = await pending;
await localState.onCommand({
command: {
index: 0,
input: '',
target: '',
verb: META_DEBUG,
},
});

const output = await pending;
expect(output.line).to.equal('state: foo-0');
});

Expand All @@ -192,15 +211,22 @@ describe('local state service', () => {
});

const pending = onceEvent<StateOutputEvent>(events, EVENT_STATE_OUTPUT);
await localState.doDebug();
await localState.onCommand({
command: {
index: 0,
input: '',
target: '',
verb: META_DEBUG,
},
});
const output = await pending;

expect(output.line).to.equal('meta.debug.none');
});
});

describe('graph command', () => {
it('should print graph for graph', async () => {
it('should print graph with state', async () => {
const container = await getTestContainer(new CoreModule());
const localState = await container.create(LocalStateService);
await localState.start();
Expand All @@ -212,9 +238,16 @@ describe('local state service', () => {

await localState.doCreate(TEST_WORLD.meta.id, 1);
const pending = onceEvent<LoaderSaveEvent>(events, EVENT_LOADER_SAVE);
await localState.doGraph('test://url');
const output = await pending;
await localState.onCommand({
command: {
index: 0,
input: '',
target: 'test://url',
verb: META_GRAPH,
},
});

const output = await pending;
expect(output.data).to.include('strict digraph');
expect(output.path).to.equal('test://url');
});
Expand All @@ -225,14 +258,17 @@ describe('local state service', () => {
await localState.start();

const events = await container.create<EventBus, BaseOptions>(INJECT_EVENT);
events.emit(EVENT_LOADER_WORLD, {
world: TEST_WORLD,
const pending = onceEvent<StateOutputEvent>(events, EVENT_STATE_OUTPUT);
await localState.onCommand({
command: {
index: 0,
input: '',
target: 'test://url',
verb: META_GRAPH,
},
});

const pending = onceEvent<StateOutputEvent>(events, EVENT_STATE_OUTPUT);
await localState.doGraph('test://url');
const output = await pending;

expect(output.line).to.equal('meta.graph.none');
});
});
Expand All @@ -244,17 +280,13 @@ describe('local state service', () => {
await localState.start();

const events = await container.create<EventBus, BaseOptions>(INJECT_EVENT);
events.emit(EVENT_LOADER_WORLD, {
world: TEST_WORLD,
});

const pending = onceEvent<StateOutputEvent>(events, EVENT_STATE_OUTPUT);
await localState.doHelp({
await localState.onCommand({
command: {
index: 0,
input: '',
target: '',
verb: VERB_WAIT,
verb: META_HELP,
},
});

Expand Down Expand Up @@ -285,13 +317,13 @@ describe('local state service', () => {

await localState.doCreate(TEST_WORLD.meta.id, 1);
const pending = onceEvent<StateOutputEvent>(events, EVENT_STATE_OUTPUT);
await localState.doHelp({
await localState.onCommand({
actor,
command: {
index: 0,
input: '',
target: '',
verb: VERB_WAIT,
verb: META_HELP,
},
room,
});
Expand All @@ -311,15 +343,53 @@ describe('local state service', () => {
});

describe('quit command', () => {
xit('should emit quit event and resolve stop');
it('should emit quit event and resolve stop', async () => {
const container = await getTestContainer(new CoreModule());
const localState = await container.create(LocalStateService);
await localState.start();

const pending = localState.stop();
await localState.onCommand({
command: {
index: 0,
input: '',
target: '',
verb: META_QUIT,
},
});

return expect(pending).to.eventually.equal(undefined);
});
});

describe('save command', () => {
xit('should save state to path');
});

describe('worlds command', () => {
xit('should print loaded worlds');
it('should print loaded worlds', async () => {
const container = await getTestContainer(new CoreModule());
const localState = await container.create(LocalStateService);
await localState.start();

const events = await container.create<EventBus, BaseOptions>(INJECT_EVENT);
events.emit(EVENT_LOADER_WORLD, {
world: TEST_WORLD,
});

const pending = onceEvent<StateOutputEvent>(events, EVENT_STATE_OUTPUT);
await localState.onCommand({
command: {
index: 0,
input: '',
target: '',
verb: META_WORLDS,
},
});

const output = await pending;
expect(output.line).to.equal('meta.world');
});
});

describe('state step', () => {
Expand Down

0 comments on commit 54d67bc

Please sign in to comment.