Skip to content

Commit

Permalink
improve: minor code cleanup after code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
issa-tseng committed Feb 19, 2021
1 parent 7ae9f18 commit 9d47408
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/model/frames/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Problem = require('../../util/problem');

class Submission extends Frame.define(
table('submissions'),
'id', readable, 'formId', readable,
'id', 'formId',
'instanceId', readable, 'submitterId', readable,
'deviceId', readable, 'createdAt', readable,
'updatedAt', readable,
Expand Down
4 changes: 3 additions & 1 deletion lib/model/migrations/20210120-01-instance-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const up = async (db) => {
await Promise.all(work);
};

const down = () => {};
const down = (db) => db.schema.table('submission_defs', (sds) => {
sds.dropColumn('instanceName');
});

module.exports = { up, down };

6 changes: 3 additions & 3 deletions lib/worker/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const runner = (container, jobMap) => {
const logname = `${event.action}::${loggedAt}::${event.acteeId}`;
process.stdout.write(`[${(new Date()).toISOString()}] start processing event ${logname} (${jobs.length} jobs)\n`);
container.transacting((tc) => timebound(Promise.all(jobs.map((f) => f(tc, event))))
.then(() => tc.run(sql`update audits set processed=now() where id=${event.id}`)))
.then(() => tc.run(sql`update audits set processed=clock_timestamp() where id=${event.id}`)))
.then(() => { process.stdout.write(`[${(new Date()).toISOString()}] finish processing event ${logname}\n`); })
.catch((err) => {
// Something Bad has happened and we'd like to log the error if we can,
Expand All @@ -44,7 +44,7 @@ const runner = (container, jobMap) => {
}
/* eslint-enable */

return run(sql`update audits set claimed=null, failures=${event.failures + 1}, "lastFailure"=now() where id=${event.id}`)
return run(sql`update audits set claimed=null, failures=${event.failures + 1}, "lastFailure"=clock_timestamp() where id=${event.id}`)
.then(() => resolve());
})
.then(reschedule, reschedule);
Expand All @@ -65,7 +65,7 @@ with q as
order by "loggedAt" asc
limit 1
for update)
update audits set claimed=now() from q where audits.id=q.id returning *`)
update audits set claimed=clock_timestamp() from q where audits.id=q.id returning *`)
.then(head);

// main loop. kicks off a check and attempts to process the result of the check.
Expand Down
2 changes: 1 addition & 1 deletion test/integration/api/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,7 @@ describe('api: /projects/:id/forms', () => {
asChelsea.get('/v1/projects/1/forms/simple/versions')
.expect(403))));

it('should list all versions', testService((service, XXXXX) =>
it('should list all versions', testService((service) =>
service.login('alice', (asAlice) =>
asAlice.post('/v1/projects/1/forms/simple/draft')
.send(testData.forms.simple.replace('id="simple"', 'id="simple" version="2"'))
Expand Down
2 changes: 1 addition & 1 deletion test/integration/api/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe('api: /projects', () => {
audit.isDefined().should.equal(true);
audit.get().actorId.should.equal(user.body.id);
audit.get().details.data.name.should.equal('Test Project');
return one(sql`select * from projects where "acteeId"=${audit.get().acteeId}`)
return one(sql`select * from projects where "acteeId"=${audit.get().acteeId}`)
.then((project) => { project.id.should.equal(body.id); });
})))));
});
Expand Down
7 changes: 3 additions & 4 deletions test/integration/api/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ const { testService } = require('../setup');

describe('api: /sessions', () => {
describe('POST', () => {
it('should return a new session if the information is valid', testService((service) => {
return service.post('/v1/sessions')
it('should return a new session if the information is valid', testService((service) =>
service.post('/v1/sessions')
.send({ email: 'chelsea@opendatakit.org', password: 'chelsea' })
.expect(200)
.then(({ body }) => {
body.should.be.a.Session();
});
}));
})));

it('should treat email addresses case insensitively', testService((service) =>
service.post('/v1/sessions')
Expand Down
2 changes: 0 additions & 2 deletions test/unit/model/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ describe('container', () => {
done();
});
});
});

describe('query modules', () => {
it('should provide database context to query modules', (done) => {
const module = { proc: (x) => ({ db }) => Promise.resolve(x + db) };
const { injected } = injector({ db: 7 }, { injected: module });
Expand Down
2 changes: 1 addition & 1 deletion test/unit/util/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('util/db', () => {
const T = Frame.define(table('frames'), 'x', 'y');
const U = Frame.define(into('extra'), 'z');
it('should generate fields', () => {
unjoiner(Frame.define(table('frames'), 'x', 'y'), Frame.define('z'))
unjoiner(T, U)
.fields.should.eql(sql`frames."x" as "frames!x",frames."y" as "frames!y","z" as "z"`);
});

Expand Down

0 comments on commit 9d47408

Please sign in to comment.