-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[repo] chore: add
User-Agent
to responses (#1285)
## Linked issues closes: #1281 ## Details add `User-Agent` header to responses for telemetry purposes.
- Loading branch information
Showing
5 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import http from 'http'; | ||
import assert from 'assert'; | ||
import sinon from 'sinon'; | ||
import axios from 'axios'; | ||
import express from 'express'; | ||
|
||
import { TeamsAdapter } from './TeamsAdapter'; | ||
|
||
describe('TeamsAdapter', () => { | ||
let sandbox: sinon.SinonSandbox; | ||
const app = express(); | ||
let server: http.Server; | ||
let adapter: TeamsAdapter; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
adapter = new TeamsAdapter(); | ||
|
||
app.post('/api/messages', async (req, res) => { | ||
await adapter.process(req, res, async () => {}); | ||
}); | ||
|
||
server = app.listen(80); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.reset(); | ||
server.close(); | ||
}); | ||
|
||
describe('process', () => { | ||
it('should add `User-Agent` header to response', async () => { | ||
sandbox.stub(adapter, <any>'processActivity').resolves({ status: 200 }); | ||
let userAgent: string | undefined; | ||
|
||
try { | ||
const res = await axios.post('/api/messages', { | ||
type: 'invoke', | ||
localTimezone: 'America/Los_Angeles', | ||
callerId: 'test', | ||
serviceUrl: 'test', | ||
channelId: 'test', | ||
from: { | ||
id: '123456', | ||
name: 'test' | ||
}, | ||
conversation: { | ||
id: '123456', | ||
name: 'test', | ||
conversationType: 'test', | ||
isGroup: false | ||
}, | ||
recipient: { | ||
id: '123456', | ||
name: 'test' | ||
}, | ||
text: '', | ||
label: 'invoke', | ||
valueType: 'invoke' | ||
}); | ||
|
||
userAgent = res.headers['user-agent']; | ||
} catch (err) { | ||
if (err instanceof axios.AxiosError) { | ||
userAgent = err.response?.headers['user-agent']; | ||
} | ||
} | ||
|
||
assert.strict.equal(userAgent, adapter.userAgent); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters