Skip to content

Commit 5d82a30

Browse files
committed
fix: Fix tests failing due to repo restructure/protocol changes
1 parent 231028f commit 5d82a30

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

test/gotham-node.test.ts

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ makeConnectionTests('Initalize Tests', function () {
1515
await sleep(0);
1616
const message = this.test.getLatestSent();
1717
expect(message).excluding('requestId').to.deep.equal({
18-
type: 'moduleRegistration',
18+
type: 1,
1919
moduleId: 'test-module',
2020
version: '1.0.0',
2121
dependencies: {}
@@ -30,7 +30,7 @@ makeConnectionTests('Initalize Tests', function () {
3030
await sleep(0);
3131
const message = this.test.getLatestSent();
3232
expect(message).excluding('requestId').to.deep.equal({
33-
type: 'moduleRegistration',
33+
type: 1,
3434
moduleId: 'test-module',
3535
version: '1.0.0',
3636
dependencies: {
@@ -40,31 +40,21 @@ makeConnectionTests('Initalize Tests', function () {
4040
});
4141
});
4242

43-
it('Does not allow to send other request without initializing', async function () {
44-
await expect(
45-
this.test.module.declareFunction('test', () => { })
46-
).to.be.rejectedWith(Error);
47-
await expect(
48-
this.test.module.callFunction('test', {})
49-
).to.be.rejectedWith(Error);
50-
await expect(
51-
this.test.module.registerHook('test', () => { })
52-
).to.be.rejectedWith(Error);
53-
await expect(
54-
this.test.module.triggerHook('test')
55-
).to.be.rejectedWith(Error);
56-
});
57-
5843
it('Initialize resolves correctly/Cannot initalize twice', async function () {
5944
const p = this.test.module.initialize('test-module1', '1.0.0', {});
6045
await sleep(0);
6146
const requestId = this.test.getLatestSent().requestId;
6247
this.test.conn.sendResponse({
6348
requestId,
64-
type: 'moduleRegistered'
49+
type: 2,
50+
});
51+
this.test.conn.sendResponse({
52+
requestId: '123',
53+
hook: "gotham.activated",
54+
type: 8
6555
});
6656
expect(p).to.eventually.equal(true);
67-
return await expect(
57+
return expect(
6858
this.test.module.initialize('test-module2', '1.0.0', {})
6959
).to.be.rejectedWith(Error);
7060
});
@@ -76,7 +66,7 @@ makeConnectionTests('Test if requests constructed correctly', function () {
7666
const message = this.test.getLatestSent();
7767
expect(message).excluding('requestId').to.deep.equal({
7868
function: "test_fn",
79-
type: "declareFunction"
69+
type: 9
8070
});
8171
});
8272

@@ -86,7 +76,7 @@ makeConnectionTests('Test if requests constructed correctly', function () {
8676
const message = this.test.getLatestSent();
8777
expect(message).excluding('requestId').to.deep.equal({
8878
function: "module.test_fn",
89-
type: "functionCall",
79+
type: 3,
9080
arguments: {}
9181
});
9282
});
@@ -99,7 +89,7 @@ makeConnectionTests('Test if requests constructed correctly', function () {
9989
const message = this.test.getLatestSent();
10090
expect(message).excluding('requestId').to.deep.equal({
10191
function: "module.test_fn",
102-
type: "functionCall",
92+
type: 3,
10393
arguments: {
10494
a: 1,
10595
b: 2
@@ -112,16 +102,16 @@ makeConnectionTests('Test if requests constructed correctly', function () {
112102
const message = this.test.getLatestSent();
113103
expect(message).excluding('requestId').to.deep.equal({
114104
hook: "test_hook",
115-
type: "registerHook",
105+
type: 5,
116106
});
117107
});
118108

119109
it('triggerHook', function () {
120110
this.test.module.triggerHook('test_hook');
121111
const message = this.test.getLatestSent();
122112
expect(message).excluding('requestId').to.deep.equal({
123-
type: "triggerHook",
124-
hook: 'test_hook'
113+
type: 7,
114+
hook: "test_hook",
125115
});
126116
});
127117
});
@@ -134,7 +124,7 @@ makeConnectionTests('Test if responses from gotham parsed correctly', async func
134124
await sleep(0);
135125
this.test.conn.sendResponse({
136126
requestId,
137-
type: 'functionDeclared',
127+
type: 10,
138128
function: 'test_fn'
139129
});
140130
return expect(p).to.eventually.equal(true);
@@ -145,7 +135,7 @@ makeConnectionTests('Test if responses from gotham parsed correctly', async func
145135
const requestId = this.test.getLatestSent().requestId;
146136
this.test.conn.sendResponse({
147137
requestId,
148-
type: 'hookRegistered',
138+
type: 6,
149139
});
150140

151141
return expect(p).to.eventually.equal(true);
@@ -157,7 +147,7 @@ makeConnectionTests('Test if responses from gotham parsed correctly', async func
157147
await sleep(0);
158148
this.test.conn.sendResponse({
159149
requestId: '12345',
160-
type: 'hookTriggered',
150+
type: 8,
161151
hook: 'test_hook'
162152
});
163153
// await sleep(0);
@@ -171,15 +161,15 @@ makeConnectionTests('Test if responses from gotham parsed correctly', async func
171161

172162
this.test.conn.sendResponse({
173163
requestId: '12345',
174-
type: 'functionCall',
164+
type: 3,
175165
function: 'test_fn'
176166
});
177167

178168
assert(fn.calledOnce);
179169

180170
this.test.conn.sendResponse({
181171
requestId: '12345',
182-
type: 'functionCall',
172+
type: 3,
183173
function: 'test_fn',
184174
arguments: {a : 1, b: 2}
185175
});
@@ -194,7 +184,7 @@ makeConnectionTests('Test if responses from gotham parsed correctly', async func
194184

195185
this.test.conn.sendResponse({
196186
requestId,
197-
type: 'functionResponse',
187+
type: 4,
198188
data: {
199189
a:1,
200190
b: 2

test/helpers.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ export class DummyGothamConnection extends BaseConnection {
2121

2222
}
2323

24-
sendResponse(message: any) {
25-
this.dataListener(message);
24+
sendResponse(message: object) {
25+
this.onData(
26+
Buffer.from(JSON.stringify(message))
27+
);
2628
}
2729
}
2830

@@ -33,9 +35,9 @@ export function makeConnectionTests(name: string, tests: Function, initalizeModu
3335
this.currentTest.sendFunc = sinon.fake();
3436
this.currentTest.getLatestSent = () => {
3537
if (this.currentTest) {
36-
return this.currentTest.sendFunc.getCall(0).args[0];
38+
return JSON.parse(this.currentTest.sendFunc.getCall(0).args[0].toString());
3739
} else {
38-
return this.test.sendFunc.getCall(0).args[0];
40+
return JSON.parse(this.test.sendFunc.getCall(0).args[0].toString());
3941
}
4042
}
4143
sinon.replace(this.currentTest.conn, 'send', this.currentTest.sendFunc);
@@ -50,7 +52,12 @@ export function makeConnectionTests(name: string, tests: Function, initalizeModu
5052
const requestId = this.currentTest.sendFunc.getCall(0).args[0].requestId;
5153
this.currentTest.conn.sendResponse({
5254
requestId,
53-
type: 'moduleRegistered'
55+
type: 2,
56+
});
57+
this.currentTest.conn.sendResponse({
58+
requestId: '123',
59+
hook: "gotham.activated",
60+
type: 8
5461
});
5562
await sleep(0);
5663
this.currentTest.sendFunc.resetHistory();

0 commit comments

Comments
 (0)