Skip to content

Commit 7c4b3a8

Browse files
committed
fix: Enable more tests
1 parent aaf6419 commit 7c4b3a8

File tree

1 file changed

+100
-100
lines changed

1 file changed

+100
-100
lines changed

test/orchestrator/connect/socket-server.test.ts

Lines changed: 100 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -61,106 +61,106 @@ describe('Connect server tests', () => {
6161
});
6262
});
6363

64-
// it('Will not create initial connection on the wrong connection code', async () => {
65-
// const reporter = new MockReporter();
66-
// await fakeLogin();
67-
//
68-
// await new Promise<void>((done) => {
69-
// ConnectOrchestrator.run('codify', reporter, false, async (connectionCode: string, server: Server) => {
70-
// expect(connectionCode).to.be.a('string');
71-
//
72-
// try {
73-
// const socket = new WebSocket(`ws://localhost:${config.connectServerPort}/ws`, ['random code']);
74-
// } catch(e) {
75-
// expect(e.message).to.contain('Invalid Sec-WebSocket-Protocol value')
76-
// server.close();
77-
// done();
78-
// }
79-
// });
80-
// });
81-
// });
82-
//
83-
// it('Will not allow a new session on the wrong code', async () => {
84-
// const reporter = new MockReporter();
85-
// await fakeLogin();
86-
//
87-
// await new Promise<void>((done) => {
88-
// startServer(reporter, async (connectionCode, clientId, server) => {
89-
// const sessionResponse = await fetch(`http://localhost:${config.connectServerPort}/session`, {
90-
// method: 'POST',
91-
// headers: { 'Authorization': 'random-code', 'Content-Type': 'application/json' },
92-
// body: JSON.stringify({ clientId })
93-
// });
94-
//
95-
// expect(sessionResponse.ok).to.be.false;
96-
//
97-
// server.close();
98-
// done();
99-
// });
100-
// });
101-
// });
102-
//
103-
// it('Will not allow a new command on the wrong code', async () => {
104-
// const reporter = new MockReporter();
105-
// await fakeLogin();
106-
//
107-
// await new Promise<void>((done) => {
108-
// startSession(reporter, async (connectionCode, clientId, server, socket, sessionId) => {
109-
// const commandResponse = await fetch(`http://localhost:${config.connectServerPort}/plan/${sessionId}/start`, {
110-
// method: 'POST',
111-
// headers: { 'Authorization': 'random-code', 'Content-Type': 'application/json' },
112-
// body: JSON.stringify({
113-
// config: [
114-
// {
115-
// type: 'homebrew',
116-
// formulae: ['zsh']
117-
// }
118-
// ]
119-
// })
120-
// });
121-
//
122-
// expect(commandResponse.ok).to.be.false;
123-
//
124-
// server.close();
125-
// done();
126-
// });
127-
// });
128-
// });
129-
//
130-
// it('Can handle a new action session (terminal)', async () => {
131-
// const reporter = new MockReporter();
132-
// await fakeLogin();
133-
//
134-
// await new Promise<void>((done) => {
135-
// startServer(reporter, async (connectionCode, clientId, server) => {
136-
// const sessionResponse = await fetch(`http://localhost:${config.connectServerPort}/session`, {
137-
// method: 'POST',
138-
// headers: { 'Authorization': `${connectionCode}`, 'Content-Type': 'application/json' },
139-
// body: JSON.stringify({ clientId })
140-
// });
141-
//
142-
// expect(sessionResponse.ok).to.be.true;
143-
// const { sessionId } = await sessionResponse.json();
144-
// expect(sessionId).to.be.a('string');
145-
//
146-
// const socket = new WebSocket(`ws://localhost:${config.connectServerPort}/ws/session/${sessionId}`, [connectionCode]);
147-
//
148-
// socket.onmessage = (message) => {
149-
// expect(message).to.not.be.null;
150-
// }
151-
//
152-
// const commandResponse = await fetch(`http://localhost:${config.connectServerPort}/terminal/${sessionId}/start`, {
153-
// method: 'POST',
154-
// headers: { 'Authorization': `${connectionCode}`, 'Content-Type': 'application/json' },
155-
// });
156-
//
157-
// expect(commandResponse.ok).to.be.true;
158-
// server.close();
159-
// done();
160-
// });
161-
// });
162-
// });
163-
//
64+
it('Will not create initial connection on the wrong connection code', async () => {
65+
const reporter = new MockReporter();
66+
await fakeLogin();
67+
68+
await new Promise<void>((done) => {
69+
ConnectOrchestrator.run('codify', reporter, false, async (connectionCode: string, server: Server) => {
70+
expect(connectionCode).to.be.a('string');
71+
72+
try {
73+
const socket = new WebSocket(`ws://localhost:${config.connectServerPort}/ws`, ['random code']);
74+
} catch(e) {
75+
expect(e.message).to.contain('Invalid Sec-WebSocket-Protocol value')
76+
server.close();
77+
done();
78+
}
79+
});
80+
});
81+
});
82+
83+
it('Will not allow a new session on the wrong code', async () => {
84+
const reporter = new MockReporter();
85+
await fakeLogin();
86+
87+
await new Promise<void>((done) => {
88+
startServer(reporter, async (connectionCode, clientId, server) => {
89+
const sessionResponse = await fetch(`http://localhost:${config.connectServerPort}/session`, {
90+
method: 'POST',
91+
headers: { 'Authorization': 'random-code', 'Content-Type': 'application/json' },
92+
body: JSON.stringify({ clientId })
93+
});
94+
95+
expect(sessionResponse.ok).to.be.false;
96+
97+
server.close();
98+
done();
99+
});
100+
});
101+
});
102+
103+
it('Will not allow a new command on the wrong code', async () => {
104+
const reporter = new MockReporter();
105+
await fakeLogin();
106+
107+
await new Promise<void>((done) => {
108+
startSession(reporter, async (connectionCode, clientId, server, socket, sessionId) => {
109+
const commandResponse = await fetch(`http://localhost:${config.connectServerPort}/plan/${sessionId}/start`, {
110+
method: 'POST',
111+
headers: { 'Authorization': 'random-code', 'Content-Type': 'application/json' },
112+
body: JSON.stringify({
113+
config: [
114+
{
115+
type: 'homebrew',
116+
formulae: ['zsh']
117+
}
118+
]
119+
})
120+
});
121+
122+
expect(commandResponse.ok).to.be.false;
123+
124+
server.close();
125+
done();
126+
});
127+
});
128+
});
129+
130+
it('Can handle a new action session (terminal)', async () => {
131+
const reporter = new MockReporter();
132+
await fakeLogin();
133+
134+
await new Promise<void>((done) => {
135+
startServer(reporter, async (connectionCode, clientId, server) => {
136+
const sessionResponse = await fetch(`http://localhost:${config.connectServerPort}/session`, {
137+
method: 'POST',
138+
headers: { 'Authorization': `${connectionCode}`, 'Content-Type': 'application/json' },
139+
body: JSON.stringify({ clientId })
140+
});
141+
142+
expect(sessionResponse.ok).to.be.true;
143+
const { sessionId } = await sessionResponse.json();
144+
expect(sessionId).to.be.a('string');
145+
146+
const socket = new WebSocket(`ws://localhost:${config.connectServerPort}/ws/session/${sessionId}`, [connectionCode]);
147+
148+
socket.onmessage = (message) => {
149+
expect(message).to.not.be.null;
150+
}
151+
152+
const commandResponse = await fetch(`http://localhost:${config.connectServerPort}/terminal/${sessionId}/start`, {
153+
method: 'POST',
154+
headers: { 'Authorization': `${connectionCode}`, 'Content-Type': 'application/json' },
155+
});
156+
157+
expect(commandResponse.ok).to.be.true;
158+
server.close();
159+
done();
160+
});
161+
});
162+
});
163+
164164
it('Can handle a new action session (plan)', async () => {
165165
const reporter = new MockReporter();
166166
await fakeLogin();

0 commit comments

Comments
 (0)