Skip to content

Commit

Permalink
Include questionCount in response when creating queue (#87)
Browse files Browse the repository at this point in the history
* fix the queue creation endpoint

* add change log entry

* fixed change log, replace findOne by findById

* Fix changelog ordering

* Add tests for questionCount on queue creation
  • Loading branch information
zwang180 authored and nwalters512 committed Mar 31, 2018
1 parent cebd5d7 commit 7aca9a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ with the current date and the next changes should go under a **[Next]** header.
* Show queue name and location on queue page. ([@sgorse](https://github.com/sgorse) in [#81](https://github.com/illinois/queue/pull/81))
* Add ability to edit existing queues. ([@zwang180](https://github.com/zwang180) in [#78](https://github.com/illinois/queue/pull/78))
* Fix [#89](https://github.com/illinois/queue/issues/89) by only checking in one queue for another question being answered by the same user. ([@nwalters512](https://github.com/nwalters512) in [#90](https://github.com/illinois/queue/pull/90))
* Correctly display number of questions when first creating a queue. ([@zwang180](https://github.com/zwang180) in [#84](https://github.com/illinois/queue/pull/84))

## 28 March 2018

Expand Down
8 changes: 5 additions & 3 deletions api/queues.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,21 @@ router.post(
]),
failIfErrors,
],
(req, res, _next) => {
async (req, res, _next) => {
const { id: courseId } = res.locals.course
const data = matchedData(req)

const queue = Queue.build({
const queue = await Queue.create({
name: data.name,
location: data.location,
fixedLocation: data.fixedLocation === true,
courseId,
createdByUserId: res.locals.userAuthn.id,
})

queue.save().then(newQueue => res.status(201).json(newQueue))
Queue.scope('questionCount')
.findById(queue.id)
.then(newQueue => res.status(201).json(newQueue))
}
)

Expand Down
2 changes: 2 additions & 0 deletions api/queues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('Queues API', () => {
expect(res.statusCode).toBe(201)
expect(res.body.name).toBe('CS225 Queue 2')
expect(res.body.location).toBe('Where')
expect(res.body.questionCount).toBe(0)
})

test('succeeds for course staff', async () => {
Expand All @@ -112,6 +113,7 @@ describe('Queues API', () => {
expect(res.statusCode).toBe(201)
expect(res.body.name).toBe('CS225 Queue 2')
expect(res.body.location).toBe('Where')
expect(res.body.questionCount).toBe(0)
})

test('fails if name is missing', async () => {
Expand Down

0 comments on commit 7aca9a4

Please sign in to comment.