diff --git a/src/receivers/HTTPReceiver.spec.ts b/src/receivers/HTTPReceiver.spec.ts index 02f2e3573..685e8eb37 100644 --- a/src/receivers/HTTPReceiver.spec.ts +++ b/src/receivers/HTTPReceiver.spec.ts @@ -71,6 +71,8 @@ describe('HTTPReceiver', function () { }); assert.isNotNull(receiver); }); + }); + describe('request handling', function () { it('should invoke installer generateInstallUrl if a request comes into the install path', async function () { // Arrange const installProviderStub = sinon.createStubInstance(InstallProvider); @@ -113,7 +115,7 @@ describe('HTTPReceiver', function () { assert(installProviderStub.generateInstallUrl.calledWith(sinon.match({ metadata, scopes, userScopes }))); assert.isTrue(writeHead.calledWith(200)); }); - it('should rediect installers if directInstallEnabled is true', async function () { + it('should redirect installers if directInstallEnabled is true', async function () { // Arrange const installProviderStub = sinon.createStubInstance(InstallProvider); const overrides = mergeOverrides( @@ -156,7 +158,52 @@ describe('HTTPReceiver', function () { assert(installProviderStub.generateInstallUrl.calledWith(sinon.match({ metadata, scopes, userScopes }))); assert.isTrue(writeHead.calledWith(302, sinon.match.object)); }); - it('should return a 404 if a request comes into neither the install path nor the redirect URI path', async function () { + it('should invoke installer handler if a request comes into the redirect URI path', async function () { + // Arrange + const installProviderStub = sinon.createStubInstance(InstallProvider, { + handleCallback: sinon.stub().resolves() as unknown as Promise, + }); + const overrides = mergeOverrides( + withHttpCreateServer(this.fakeCreateServer), + withHttpsCreateServer(sinon.fake.throws('Should not be used.')), + ); + const HTTPReceiver = await importHTTPReceiver(overrides); + + const metadata = 'this is bat country'; + const scopes = ['channels:read']; + const userScopes = ['chat:write']; + const callbackOptions = {}; + const receiver = new HTTPReceiver({ + logger: noopLogger, + clientId: 'my-clientId', + clientSecret: 'my-client-secret', + signingSecret: 'secret', + stateSecret: 'state-secret', + scopes, + installerOptions: { + authVersion: 'v2', + redirectUriPath: '/heyo', + callbackOptions, + metadata, + userScopes, + }, + }); + assert.isNotNull(receiver); + receiver.installer = installProviderStub as unknown as InstallProvider; + const fakeReq: IncomingMessage = sinon.createStubInstance(IncomingMessage) as IncomingMessage; + fakeReq.url = '/heyo'; + fakeReq.headers = { host: 'localhost' }; + fakeReq.method = 'GET'; + const fakeRes: ServerResponse & {} = sinon.createStubInstance(ServerResponse) as unknown as ServerResponse; + const writeHead = sinon.fake(); + const end = sinon.fake(); + fakeRes.writeHead = writeHead; + fakeRes.end = end; + /* eslint-disable-next-line @typescript-eslint/await-thenable */ + await receiver.requestListener(fakeReq, fakeRes); + assert(installProviderStub.handleCallback.calledWith(fakeReq, fakeRes, callbackOptions)); + }); + it('should throw if a request comes into neither the install path nor the redirect URI path', async function () { // Arrange const installProviderStub = sinon.createStubInstance(InstallProvider); const overrides = mergeOverrides(