From 5cb2fd6ddd5a43d9fe0fc2f56306a556d6f55281 Mon Sep 17 00:00:00 2001 From: Xavier Damman Date: Thu, 15 Feb 2018 23:06:20 +0100 Subject: [PATCH 1/2] add limit and offset to allEvents + fix for lru cache content type --- server/graphql/queries.js | 10 ++++++---- server/middleware/lru_cache.js | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/server/graphql/queries.js b/server/graphql/queries.js index a4bd760b430..26926b66c39 100644 --- a/server/graphql/queries.js +++ b/server/graphql/queries.js @@ -420,9 +420,9 @@ const queries = { allEvents: { type: new GraphQLList(CollectiveInterfaceType), args: { - slug: { - type: GraphQLString - } + slug: { type: GraphQLString }, + limit: { type: GraphQLInt }, + offset: { type: GraphQLInt } }, resolve(_, args) { if (args.slug) { @@ -430,7 +430,9 @@ const queries = { .findBySlug(args.slug, { attributes: ['id'] }) .then(collective => models.Collective.findAll({ where: { ParentCollectiveId: collective.id, type: 'EVENT' }, - order: [['startsAt', 'DESC'], ['createdAt', 'DESC']] + order: [['startsAt', 'DESC'], ['createdAt', 'DESC']], + limit: args.limit || 10, + offset: args.offset || 0 })) .catch(e => { console.error(e.message); diff --git a/server/middleware/lru_cache.js b/server/middleware/lru_cache.js index 700520d748e..df7e21ed0d8 100644 --- a/server/middleware/lru_cache.js +++ b/server/middleware/lru_cache.js @@ -2,6 +2,8 @@ import LRUCache from 'lru-cache'; import { hashCode } from '../lib/utils'; import { EventEmitter } from 'events'; +import debugLib from 'debug'; +const debug = debugLib("cache"); const cache = LRUCache({ max: 1000, @@ -31,8 +33,11 @@ export default () => { let cached = cache.get(checksum); if (cached) { + debug("cache hit", cached.status); switch (cached.status) { case 'finished': + debug("sending response", cached.contentType, cached.response); + res.setHeader("content-type", cached.contentType); return res.send(new Buffer(cached.response, "base64")); case 'running': return cached.once('finished', () => { @@ -51,7 +56,11 @@ export default () => { if (req.cached && req.checksum) { req.cached.status = 'finished'; req.cached.response = data; + if (typeof data === 'object') { + req.cached.contentType = "application/json; charset=utf-8"; + } req.cached.emit('finished'); + debug("set cache", req.checksum, req.cached); cache.set(req.checksum, req.cached) } temp.apply(this,arguments); From 40014498aed5a2657a44e95aa0665979036ebc96 Mon Sep 17 00:00:00 2001 From: Xavier Damman Date: Thu, 15 Feb 2018 23:36:46 +0100 Subject: [PATCH 2/2] debug failing tests --- test/email.routes.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/email.routes.test.js b/test/email.routes.test.js index 033780ea7a3..2df2b936e05 100644 --- a/test/email.routes.test.js +++ b/test/email.routes.test.js @@ -122,12 +122,15 @@ describe("email.routes.test", () => { it("forwards the email for approval to the core members", () => { const spy = sandbox.spy(emailLib, 'send'); - return request(app) .post('/webhooks/mailgun') .send(webhookBodyPayload) .then((res) => { expect(res.statusCode).to.equal(200); + if (spy.args[0][1] !== 'admins@testcollective.opencollective.com') { + console.log(">>> emailLib.send spy.callCount", spy.callCount); + utils.inspectSpy(spy, 4); + } expect(spy.args[0][1]).to.equal('admins@testcollective.opencollective.com'); const emailSentTo = [spy.args[0][3].bcc,spy.args[1][3].bcc]; expect(emailSentTo.indexOf(usersData[0].email) !== -1).to.be.true;