Skip to content

Commit

Permalink
streams/:id does not return deleted stream
Browse files Browse the repository at this point in the history
  • Loading branch information
rassokhin-s committed Jul 24, 2023
1 parent 7aacdf0 commit bd2004b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 7 additions & 1 deletion core/streams/dao/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ async function get (idOrWhere, options = {}) {
const include = options.fields && options.fields.length > 0 ? availableIncludes.filter(i => options.fields.includes(i.as)) : availableIncludes
const transaction = options.transaction || null

const stream = await Stream.findOne({ where, attributes, include, paranoid: false, transaction })
const stream = await Stream.findOne({
where,
attributes,
include,
paranoid: options.onlyDeleted !== true,
transaction
})

if (!stream) {
throw new EmptyResultError('Stream not found')
Expand Down
21 changes: 17 additions & 4 deletions core/streams/get.int.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
const routes = require('.')
const models = require('../_models')
const { expressApp, seedValues, truncateNonBase } = require('../../common/testing/sequelize')
const { expressApp, seedValues, truncateNonBase, muteConsole } = require('../../common/testing/sequelize')
const request = require('supertest')

const app = expressApp()

app.use('/', routes)

beforeAll(() => {
muteConsole('warn')
})
afterEach(async () => {
await truncateNonBase(models)
})
afterAll(async () => {
await truncateNonBase(models)
await models.sequelize.close()
})

describe('GET /streams/:id', () => {
test('not found', async () => {
console.warn = jest.fn()

const response = await request(app).get('/1234')

expect(response.statusCode).toBe(404)
expect(console.warn).toHaveBeenCalled()
})

test('deleted stream not found', async () => {
const stream = { id: 'jagu1', createdById: seedValues.primaryUserId, name: 'Jaguar Station', latitude: 10.1, longitude: 101.1, altitude: 200, deletedAt: '2021-01-01T00:00:00.000Z' }
await models.Stream.create(stream)

const response = await request(app).get(`/${stream.id}`)

expect(response.statusCode).toBe(404)
expect(response.body.message).toBe('Stream not found')
})

test('readable by creator', async () => {
Expand Down

0 comments on commit bd2004b

Please sign in to comment.