-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- unit tests! - separate routers - separate mail adapters - SCSS build (update Foundation)
- Loading branch information
1 parent
6fd1f87
commit ccd90ad
Showing
23 changed files
with
2,040 additions
and
7,632 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Javascript Node CircleCI 2.0 configuration file | ||
# | ||
# Check https://circleci.com/docs/2.0/language-javascript/ for more details | ||
# | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
# specify the version you desire here | ||
- image: circleci/node:10.15 | ||
|
||
# Specify service dependencies here if necessary | ||
# CircleCI maintains a library of pre-built images | ||
# documented at https://circleci.com/docs/2.0/circleci-images/ | ||
# - image: circleci/mongo:3.4.4 | ||
|
||
working_directory: ~/repo | ||
|
||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: npm install | ||
|
||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
|
||
- run: npm run init-config | ||
|
||
# run tests! | ||
- run: npm test | ||
|
||
|
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,7 +1,7 @@ | ||
/node_modules | ||
/public/components | ||
.idea/ | ||
.c9/ | ||
/data/storage.json | ||
/data/ | ||
/app/config/config.json | ||
.DS_Store | ||
.DS_Store | ||
public/css/app.css |
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 @@ | ||
// todo |
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,16 @@ | ||
const sgMail = require('@sendgrid/mail'); | ||
|
||
module.exports = class SendGridAdapter { | ||
constructor (opts, fromAddress) { | ||
this.fromAddress = fromAddress; | ||
sgMail.setApiKey(opts['api-key']); | ||
} | ||
|
||
send (messages) { | ||
messages.forEach((message) => { | ||
message.from = this.fromAddress; | ||
}); | ||
|
||
return sgMail.sendMultiple(messages); | ||
} | ||
}; |
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,51 @@ | ||
const sinon = require('sinon'); | ||
const expect = require('chai').expect; | ||
const sgMail = require('@sendgrid/mail'); | ||
const SendGridAdapter = require('../adapters/send-grid'); | ||
|
||
describe('SendGridAdapter', () => { | ||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('constructor()', () => { | ||
it('should set the API key', () => { | ||
const stub = sandbox.stub(sgMail, 'setApiKey'); | ||
|
||
new SendGridAdapter({ | ||
'api-key': 'test-123' | ||
}, ''); | ||
|
||
expect(stub.calledWith('test-123')).to.equal(true); | ||
}); | ||
}); | ||
|
||
describe('send()', () => { | ||
it('should send messages', () => { | ||
const stub = sandbox.stub(sgMail, 'sendMultiple'); | ||
|
||
const adapter = new SendGridAdapter({ | ||
'api-key': 'test-123' | ||
}, 'sender@test.com'); | ||
|
||
adapter.send([ | ||
{ | ||
to: 'test@example.com' | ||
} | ||
]); | ||
|
||
expect(stub.calledWith([ | ||
{ | ||
to: 'test@example.com', | ||
from: 'sender@test.com' | ||
} | ||
])).to.equal(true); | ||
}); | ||
}); | ||
}); |
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,15 +1,18 @@ | ||
{ | ||
"title": "Node Secret Santa", | ||
"signup-password": false, | ||
"admin-password": "asda", | ||
"deadline": "Dec 5th", | ||
"spend-limit": "$50", | ||
|
||
"email-server": { | ||
"type": "mailgun" | ||
"type": "sendgrid", | ||
"from-address": "santa@thenorthpole.com", | ||
|
||
"options": { | ||
"api-key": "REPLACE_ME" | ||
} | ||
}, | ||
|
||
"cookie-secret": "xxxdsfsdfyyyzzz111", | ||
"session-secret": "zzzxsdfsdfxxcccc222" | ||
|
||
} | ||
} |
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,31 @@ | ||
const express = require('express'); | ||
const app = require('../lib/app'); | ||
|
||
const router = new express.Router(); | ||
|
||
router.use(app.ensureLoggedIn); | ||
|
||
router.get('/', (req, res) => { | ||
const storage = app.getStorage(); | ||
|
||
res.render('admin', { | ||
subscribers: storage.subscribers, | ||
alreadySent: app.haveEmailsAlreadySent() | ||
}); | ||
}); | ||
|
||
router.post('/create-send', (req, res) => { | ||
const list = app.createAndSendEmails(); | ||
res.render('admin-review-send', { | ||
recipients: list | ||
}); | ||
}); | ||
|
||
router.post('/re-send', (req, res) => { | ||
const list = app.resendRecipientList(); | ||
res.render('admin-review-send', { | ||
recipients: list | ||
}); | ||
}); | ||
|
||
module.exports = router; |
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,42 @@ | ||
const express = require('express'); | ||
const app = require('../lib/app'); | ||
const config = app.getConfig(); | ||
const router = new express.Router(); | ||
|
||
router.get('/', function (req, res) { | ||
res.render('index', { | ||
title: config.title, | ||
deadline: config.deadline, | ||
spendLimit: config['spend-limit'] | ||
}); | ||
}); | ||
|
||
router.post('/save', function (req, res) { | ||
app.addSubscriber({ | ||
name: req.body.name, | ||
email: req.body.email, | ||
colour: req.body.colour, | ||
animal: req.body.animal, | ||
idea: req.body.idea | ||
}); | ||
|
||
res.render('registered'); | ||
}); | ||
|
||
router.get('/login', app.ensureLoggedIn, function (req, res) { | ||
res.render('login'); | ||
}); | ||
|
||
router.post('/login', app.ensureLoggedIn, function (req, res, next) { | ||
if (req.body.password === config['admin-password']) { | ||
app.initSession(req, res); | ||
res.redirect('/admin'); | ||
next(); | ||
} else { | ||
res.render('login', { | ||
error: 'Incorrect password' | ||
}); | ||
} | ||
}); | ||
|
||
module.exports = router; |
Oops, something went wrong.