forked from CoderDojo/cp-users-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CoderDojo#173 from CoderDojo/staging
Staging sync
- Loading branch information
Showing
17 changed files
with
222 additions
and
539 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
FROM mhart/alpine-node:0.10.48 | ||
MAINTAINER butlerx <[email protected]> | ||
ENV NODE_ENV=production | ||
ARG DEP_VERSION=latest | ||
RUN apk add --update git build-base python postgresql-client | ||
RUN mkdir -p /usr/src/app | ||
RUN apk add --update git build-base python postgresql-client &&\ | ||
mkdir -p /usr/src/app | ||
WORKDIR /usr/src/app | ||
ADD . /usr/src/app | ||
COPY . /usr/src/app | ||
RUN npm install && \ | ||
npm install cp-translations@$DEP_VERSION && \ | ||
npm install cp-translations@"$DEP_VERSION" && \ | ||
apk del build-base python && \ | ||
rm -rf /tmp/* /root/.npm /root/.node-gyp | ||
EXPOSE 10306 | ||
CMD ["npm", "start"] | ||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
FROM mhart/alpine-node:0.10.48 | ||
MAINTAINER butlerx <[email protected]> | ||
ENV NODE_ENV=development | ||
RUN apk add --update git build-base python postgresql-client && \ | ||
mkdir -p /usr/src/app /usr/src/cp-translations | ||
COPY docker-entrypoint.sh /usr/src | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var async = require('async'); | ||
/** | ||
* updateAddress function - Called to update all upcoming event address upon dojo address change | ||
* By default asynchronous | ||
* @param {String} dojoId Identifier of the parent entity | ||
* @param {Object} location Object containing the information of the address | ||
* @return {Void} | ||
*/ | ||
module.exports = function (args, done) { | ||
var seneca = this; | ||
var plugin = args.role; | ||
var dojoId = args.dojoId; | ||
var location = args.location; | ||
// Retrieve all events in the future | ||
function getUpcomingEvents (wfCb) { | ||
seneca.act({role: plugin, entity: 'next-events', cmd: 'list', query: {dojoId: dojoId, useDojoAddress: true}}, | ||
function (err, events) { | ||
if (events && events.length > 0) { | ||
wfCb(null, events); | ||
} else { | ||
done(); | ||
} | ||
}); | ||
} | ||
function updateEvents (events, wfCb) { | ||
async.eachSeries(events, updateAddress, wfCb); | ||
} | ||
// Save the new address | ||
function updateAddress (event, sCb) { | ||
var payload = { | ||
id: event.id, | ||
country: location.country, | ||
city: location.city, | ||
address: location.address, | ||
position: location.position | ||
}; | ||
seneca.act({role: plugin, entity: 'event', cmd: 'save', event: payload}, sCb); | ||
} | ||
async.waterfall([ | ||
getUpcomingEvents, | ||
updateEvents | ||
], done); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
'use strict'; | ||
|
||
var lab = exports.lab = require('lab').script(); | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
chai.use(require('sinon-chai')); | ||
var sinon = require('sinon'); | ||
var _ = require('lodash'); | ||
var fn = require(__dirname + '/update-address.js'); | ||
|
||
lab.experiment('Event - Update address', { timeout: 5000 }, function () { | ||
var sandbox; | ||
var senecaStub; | ||
var updateAddress; | ||
|
||
lab.beforeEach(function (done) { | ||
sandbox = sinon.sandbox.create(); | ||
senecaStub = { | ||
act: sandbox.stub(), | ||
make: sandbox.stub() | ||
}; | ||
updateAddress = fn.bind(senecaStub); | ||
done(); | ||
}); | ||
|
||
lab.afterEach(function (done) { | ||
sandbox.restore(); | ||
done(); | ||
}); | ||
|
||
lab.test('should get next events and update addresses of those events', function (done) { | ||
// ARRANGE | ||
var dojoId = 1; | ||
var mockLocation = { | ||
address: 'aha', | ||
city: { placeName: 'place' }, | ||
country: { | ||
alpha2: 'FR', | ||
countryName: 'France' | ||
}, | ||
position: { lat: 1, lng: 1 } }; | ||
var mockEvents = [{ id: 1, name: 'event1' }]; | ||
var eventMock = _.assign({}, | ||
mockLocation, | ||
{ id: mockEvents[0].id }); | ||
// PREPARE | ||
senecaStub.act | ||
.withArgs(sinon.match({ role: 'cd-events', entity: 'next-events', cmd: 'list' })) | ||
.callsFake(function (args, cb) { | ||
expect(args.query).to.be.eql({ | ||
dojoId: dojoId, | ||
useDojoAddress: true | ||
}); | ||
cb(null, mockEvents); | ||
}); | ||
senecaStub.act | ||
.withArgs(sinon.match({ role: 'cd-events', entity: 'event', cmd: 'save' })) | ||
.callsFake(function (args, cb) { | ||
expect(args.event).to.be.eql(eventMock); | ||
cb(null, eventMock); | ||
}); | ||
// ACT | ||
updateAddress({ role: 'cd-events', dojoId: 1, location: mockLocation }, function (err, ret) { | ||
expect(err).to.be.eql(undefined); | ||
expect(ret).to.be.eql(undefined); | ||
done(); | ||
}); | ||
}); | ||
|
||
lab.test('should not save if there is no events', function (done) { | ||
// ARRANGE | ||
var dojoId = 1; | ||
var mockLocation = { | ||
address: 'aha', | ||
city: { placeName: 'place' }, | ||
country: { | ||
alpha2: 'FR', | ||
countryName: 'France' | ||
}, | ||
position: { lat: 1, lng:1 } | ||
}; | ||
var mockEvents = []; | ||
// PREPARE | ||
senecaStub.act | ||
.withArgs(sinon.match({ role: 'cd-events', entity: 'next-events', cmd: 'list' })) | ||
.callsFake(function (args, cb) { | ||
expect(args.query).to.be.eql({ | ||
dojoId: dojoId, | ||
useDojoAddress: true | ||
}); | ||
cb(null, mockEvents); | ||
}); | ||
// ACT | ||
updateAddress({role: 'cd-events', dojoId: 1, location: mockLocation}, function (err, ret) { | ||
expect(err).to.be.eql(undefined); | ||
expect(ret).to.be.eql(undefined); | ||
expect(senecaStub.act | ||
.withArgs(sinon.match({ role: 'cd-events', entity: 'event', cmd: 'save' })) | ||
).to.not.have.been.called; | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = function (args, done) { | ||
var seneca = this; | ||
var event = args.event; | ||
seneca.make$('cd/events').save$(event, done); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = function (args, done) { | ||
var seneca = this; | ||
var query = args.query; | ||
if (query) { | ||
seneca.make$('v/next_events').list$(query, done); | ||
} else { | ||
done(null, []); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
scripts/database/pg/migrations/021.do.add-useDojoAddress-field-to-cd-events.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
DO $$ | ||
BEGIN | ||
BEGIN | ||
ALTER TABLE cd_events ADD COLUMN use_dojo_address boolean; | ||
EXCEPTION | ||
WHEN duplicate_column THEN RAISE NOTICE 'column useDojoAddress already exists in cd_events.'; | ||
END; | ||
END; | ||
$$ |
13 changes: 13 additions & 0 deletions
13
scripts/database/pg/migrations/022.do.add-next-events-view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE FUNCTION f_next_events() | ||
RETURNS void AS $$ | ||
BEGIN | ||
CREATE OR REPLACE VIEW v_next_events AS ( | ||
SELECT DISTINCT ON (id) * FROM ( | ||
SELECT * FROM ( | ||
SELECT *, unnest(dates)->>'startTime' as next_date FROM cd_events | ||
) x WHERE next_date IS NOT NULL AND next_date NOT LIKE 'Invalid%' | ||
) as filtered_dates WHERE next_date > to_char(NOW(), 'YYYY-MM-DDTHH:mm:ss') ORDER BY id, next_date | ||
); | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
SELECT f_next_events(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.