Skip to content

Commit

Permalink
Fix unchanged query column names
Browse files Browse the repository at this point in the history
We switched from query.folder_id to query.folder (which is a FK to
folder.code), some of the queries related to creating queries had now
been updated
  • Loading branch information
Andrew Isherwood committed Jun 18, 2020
1 parent e47d7af commit 15a3a48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions resolvers/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ const queryResolvers = {
// If we have an ID, we're updating
if (params.hasOwnProperty('id') && params.id) {
return pool.query(
'UPDATE query SET title = $1, folder_id = $2, initiator = $3, updated_at = NOW() WHERE id = $4 RETURNING *',
[body.title, body.folder_id, body.initiator, params.id]
'UPDATE query SET title = $1, folder = $2, initiator = $3, updated_at = NOW() WHERE id = $4 RETURNING *',
[body.title, body.folder, body.initiator, params.id]
);
} else {
return pool.query(
'INSERT INTO query VALUES (DEFAULT, $1, $2, NOW(), NOW(), $3) RETURNING *',
[body.title, body.folder_id, body.initiator]
'INSERT INTO query VALUES (DEFAULT, $1, NOW(), NOW(), $2, $3) RETURNING *',
[body.title, body.initiator, body.folder]
);
}
},
Expand Down
16 changes: 8 additions & 8 deletions test/resolvers/queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ describe('Queries', () => {
done();
});
// Pass title, offset, limit, folder and label parameters
queries.allQueries({ query: { title: 'hello', offset: 20, limit: 10, folder: 'INBOX', label: 1 } });
queries.allQueries({ query: { title: 'hello', offset: 20, limit: 10, folder: 'ESCALATED', label: 1 } });
it('should be passed correct SQL including parameters', (done) => {
expect(pool.query).toBeCalledWith(
"SELECT q.* FROM query q, querylabel ql WHERE q.id = ql.query_id AND ql.label_id = $1 AND title ILIKE '%' || $2 || '%' AND folder = $3 ORDER BY updated_at DESC OFFSET $4 LIMIT $5",
[1, 'hello', 'INBOX', 20, 10]
[1, 'hello', 'ESCALATED', 20, 10]
);
done();
});
Expand All @@ -56,7 +56,7 @@ describe('Queries', () => {
// Make the call *with an ID*
queries.upsertQuery({
params: { id: 1 },
body: { title: 'Fred', folder_id: 1, initiator: 1 }
body: { title: 'Fred', folder: 'ESCALATED', initiator: 1 }
});
it('should be called', (done) => {
expect(pool.query).toHaveBeenCalled();
Expand All @@ -66,22 +66,22 @@ describe('Queries', () => {
expect(
pool.query
).toBeCalledWith(
'UPDATE query SET title = $1, folder_id = $2, initiator = $3, updated_at = NOW() WHERE id = $4 RETURNING *',
['Fred', 1, 1, 1]
'UPDATE query SET title = $1, folder = $2, initiator = $3, updated_at = NOW() WHERE id = $4 RETURNING *',
['Fred', 'ESCALATED', 1, 1]
);
done();
});
// Make the call *without an ID*
queries.upsertQuery({
params: {},
body: { title: 'Fred', folder_id: 1, initiator: 1 }
body: { title: 'Fred', folder: 'ESCALATED', initiator: 1 }
});
it('should be called as an INSERT when ID is not passed', (done) => {
expect(
pool.query
).toBeCalledWith(
'INSERT INTO query VALUES (DEFAULT, $1, $2, NOW(), NOW(), $3) RETURNING *',
['Fred', 1, 1]
'INSERT INTO query VALUES (DEFAULT, $1, NOW(), NOW(), $2, $3) RETURNING *',
['Fred', 1, 'ESCALATED']
);
done();
});
Expand Down

0 comments on commit 15a3a48

Please sign in to comment.