UNPKG

@copperjs/copper

Version:
64 lines 3.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sinon = require("sinon"); const fastify_1 = require("fastify"); const chai_1 = require("chai"); const sessionManager_1 = require("./sessionManager"); const routes_1 = require("./routes"); describe('standalone routes', () => { let fastifyInstance; beforeEach(async () => { fastifyInstance = fastify_1.fastify(); await fastifyInstance.register(routes_1.registerRoutes); await fastifyInstance.ready(); }); afterEach(async () => { await fastifyInstance.close(); }); it('should return server status', async () => { const response = await fastifyInstance.inject({ method: 'GET', url: '/status' }); chai_1.expect(response.statusCode).to.equal(200); chai_1.expect(response.body).to.equal(JSON.stringify({ ready: true, message: 'Copper Is Ready' })); }); it('should list sessions', async () => { const stub = sinon.stub(sessionManager_1.sessionManager, 'listSessions').returns([{ id: '1' }, { id: '2' }]); const response = await fastifyInstance.inject({ method: 'GET', url: '/sessions' }); chai_1.expect(response.statusCode).to.equal(200); chai_1.expect(response.body).to.equal(JSON.stringify({ status: 0, value: [{ id: '1' }, { id: '2' }] })); chai_1.expect(stub).to.have.been.calledOnce; stub.restore(); }); it('should create a session', async () => { const stub = sinon.stub(sessionManager_1.sessionManager, 'createSession').resolves({ id: '1' }); const response = await fastifyInstance.inject({ method: 'POST', url: '/session' }); chai_1.expect(response.statusCode).to.equal(200); chai_1.expect(response.body).to.equal(JSON.stringify({ status: 0, value: { id: '1', webSocketDebuggerUrl: 'ws://localhost:80/ws/1', 'goog:chromeOptions': { debuggerAddress: 'localhost:80/ws/1' }, }, sessionId: '1', })); chai_1.expect(stub).to.have.been.calledOnce; stub.restore(); }); it('should get session info', async () => { const stub = sinon.stub(sessionManager_1.sessionManager, 'getSession').returns({ id: '1' }); const response = await fastifyInstance.inject({ method: 'GET', url: '/session/1' }); chai_1.expect(response.statusCode).to.equal(200); chai_1.expect(response.body).to.equal(JSON.stringify({ status: 0, value: { id: '1' }, sessionId: '1' })); chai_1.expect(stub).to.have.been.calledOnce; stub.restore(); }); it('should remove a session', async () => { const stub = sinon.stub(sessionManager_1.sessionManager, 'removeSession').resolves({ id: '1' }); const response = await fastifyInstance.inject({ method: 'DELETE', url: '/session/1' }); chai_1.expect(response.statusCode).to.equal(200); chai_1.expect(response.body).to.equal(JSON.stringify({ status: 0, value: null, sessionId: null, state: 'success' })); chai_1.expect(stub).to.have.been.calledOnce; stub.restore(); }); }); //# sourceMappingURL=routes.test.js.map