Compare commits

...

4 Commits

Author SHA1 Message Date
standardci
7c271be310 chore(release): publish new version
- @standardnotes/auth-server@1.3.3
2022-06-28 10:09:14 +00:00
Karol Sójko
ba373ebc6b fix: change response type to html for muting marketing emails 2022-06-28 12:08:36 +02:00
Mo
c50662849b Merge pull request #4 from standardnotes/chore/pr-workflow
chore: add pr workflow
2022-06-27 17:12:23 -05:00
Mo
82da690139 chore: add pr workflow 2022-06-27 17:04:39 -05:00
5 changed files with 51 additions and 13 deletions

21
.github/workflows/pr.yml vendored Normal file
View File

@@ -0,0 +1,21 @@
name: Pull Request
on:
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies
run: yarn install
- name: ESLint
run: yarn lint
- name: Build
run: yarn build
- name: Test
run: yarn test

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.3.3](https://github.com/standardnotes/auth/compare/@standardnotes/auth-server@1.3.2...@standardnotes/auth-server@1.3.3) (2022-06-28)
### Bug Fixes
* change response type to html for muting marketing emails ([ba373eb](https://github.com/standardnotes/auth/commit/ba373ebc6b3038f7de2fab40f0429a655dbe2499))
## [1.3.2](https://github.com/standardnotes/auth/compare/@standardnotes/auth-server@1.3.1...@standardnotes/auth-server@1.3.2) (2022-06-27)
**Note:** Version bump only for package @standardnotes/auth-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/auth-server",
"version": "1.3.2",
"version": "1.3.3",
"engines": {
"node": ">=16.0.0 <17.0.0"
},

View File

@@ -19,6 +19,7 @@ describe('InternalController', () => {
let muteMarketingEmails: MuteMarketingEmails
let request: express.Request
let response: express.Response
let user: User
const createController = () =>
@@ -48,6 +49,11 @@ describe('InternalController', () => {
body: {},
params: {},
} as jest.Mocked<express.Request>
response = {} as jest.Mocked<express.Response>
response.setHeader = jest.fn()
response.status = jest.fn().mockReturnThis()
response.send = jest.fn()
})
it('should get user features', async () => {
@@ -170,26 +176,27 @@ describe('InternalController', () => {
it('should mute marketing emails user setting', async () => {
request.params.settingUuid = '1-2-3'
muteMarketingEmails.execute = jest.fn().mockReturnValue({ success: true })
muteMarketingEmails.execute = jest.fn().mockReturnValue({ success: true, message: 'foobar' })
const httpResponse = <results.JsonResult>await createController().muteMarketingEmails(request)
const result = await httpResponse.executeAsync()
await createController().muteMarketingEmails(request, response)
expect(muteMarketingEmails.execute).toHaveBeenCalledWith({ settingUuid: '1-2-3' })
expect(result.statusCode).toEqual(200)
expect(response.setHeader).toHaveBeenCalledWith('content-type', 'text/html')
expect(response.send).toHaveBeenCalledWith('foobar')
})
it('should not mute marketing emails user setting if it does not exist', async () => {
request.params.settingUuid = '1-2-3'
muteMarketingEmails.execute = jest.fn().mockReturnValue({ success: false })
muteMarketingEmails.execute = jest.fn().mockReturnValue({ success: false, message: 'foobar' })
const httpResponse = <results.JsonResult>await createController().muteMarketingEmails(request)
const result = await httpResponse.executeAsync()
await createController().muteMarketingEmails(request, response)
expect(muteMarketingEmails.execute).toHaveBeenCalledWith({ settingUuid: '1-2-3' })
expect(result.statusCode).toEqual(404)
expect(response.setHeader).toHaveBeenCalledWith('content-type', 'text/html')
expect(response.status).toHaveBeenCalledWith(404)
expect(response.send).toHaveBeenCalledWith('foobar')
})
})

View File

@@ -1,4 +1,4 @@
import { Request } from 'express'
import { Request, Response } from 'express'
import { inject } from 'inversify'
import {
BaseHttpController,
@@ -84,16 +84,20 @@ export class InternalController extends BaseHttpController {
}
@httpGet('/settings/marketing-emails/:settingUuid/mute')
async muteMarketingEmails(request: Request): Promise<results.JsonResult> {
async muteMarketingEmails(request: Request, response: Response): Promise<void> {
const { settingUuid } = request.params
const result = await this.doMuteMarketingEmails.execute({
settingUuid,
})
response.setHeader('content-type', 'text/html')
if (result.success) {
return this.json({ message: result.message })
response.send(result.message)
return
}
return this.json({ message: result.message }, 404)
response.status(404).send(result.message)
}
}