Skip to content

Commit

Permalink
[fix] tests, release canidate
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-wyatt committed Jul 24, 2018
1 parent 44b501c commit 9e8757f
Show file tree
Hide file tree
Showing 21 changed files with 626 additions and 192 deletions.
85 changes: 85 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#

version: 2

defaults: &defaults
working_directory: ~/fabrix
docker:
- image: circleci/node:10.0.0
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: ""
- image: circleci/postgres:9.6.2-alpine
environment:
POSTGRES_DB: Sequelize
POSTGRES_USER: root
POSTGRES_PASSWORD: ""

jobs:
test:
<<: *defaults
steps:
- checkout
- run:
name: update-npm
command: 'sudo npm install -g npm@5'
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: install-npm-wee
command: npm install
- run:
name: install-npm-sqlite
command: npm install [email protected]
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
- run:
name: test
command: npm test
- run:
name: code-coverage
command: './node_modules/.bin/nyc report --reporter=text-lcov'
- store_artifacts:
path: test-results.xml
prefix: tests
- store_artifacts:
path: coverage
prefix: coverage
- store_test_results:
path: test-results.xml
- persist_to_workspace:
root: ~/fabrix
paths: .
deploy:
<<: *defaults
steps:
- attach_workspace:
at: ~/fabrix
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$npm_TOKEN" > ~/fabrix/.npmrc
- run:
name: Publish package
command: npm publish

workflows:
version: 2
test-deploy:
jobs:
- test:
filters:
tags:
only: /^v.*/
- deploy:
requires:
- test
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2016 scott-wyatt <[email protected]> (https://cali-style.com)
Copyright (c) 2018 CST <[email protected]>
2018 Scott Wyatt <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 0 additions & 10 deletions circle.yml

This file was deleted.

15 changes: 12 additions & 3 deletions lib/NotificationsSpool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class NotificationsSpool extends Spool {
* Validates Configs
*/
async validate () {
const requiredSpools = ['express', 'sequelize']
const requiredSpools = ['express', 'sequelize', 'passport', 'permissions']
const spools = Object.keys(this.app.spools)

if (!spools.some(v => requiredSpools.indexOf(v) >= 0)) {
return Promise.reject(new Error(`spool-permissions requires spools: ${ requiredSpools.join(', ') }!`))
return Promise.reject(new Error(`spool-notifications requires spools: ${ requiredSpools.join(', ') }!`))
}

// Configs
Expand All @@ -50,16 +50,25 @@ export class NotificationsSpool extends Spool {
return Promise.reject(new Error('No configuration found at config.generics.email_provider.options.host!'))
}

if (!this.app.config.get('generics.render_service')) {
this.app.log.warn('config.generics.render_service is not set, notifications will load generics-render')
}

return Promise.all([
Validator.validateNotifications.config(this.app.config.get('notifications'))
])
}

async configure () {
return Promise.all([
Notifications.configure(this.app),
Notifications.resolveGenerics(this.app)
])
}

sanity() {
if (!this.app.config.get('generics.render_service.adapter')) {
throw new Error('config.generics.render_service was not set or was unset incorrectly')
}
}
}

14 changes: 7 additions & 7 deletions lib/api/controllers/NotificationController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FabrixController as Controller } from '@fabrix/fabrix/dist/common'
import { ModelError } from '@fabrix/spool-sequelize/dist/errors'

/**
* @module NotificationController
Expand All @@ -22,7 +23,7 @@ export class NotificationController extends Controller {
Notification.findByIdDefault(req.params.id, {})
.then(notification => {
if (!notification) {
throw new Error(`Notification id ${ req.params.id } not found`)
throw new ModelError('E_NOT_FOUND', `Notification id ${ req.params.id } not found`)
}
return this.app.services.PermissionsService.sanitizeResult(req, notification)
})
Expand Down Expand Up @@ -51,7 +52,7 @@ export class NotificationController extends Controller {
Notification.findByTokenDefault(req.params.token)
.then(notification => {
if (!notification) {
throw new Error(`Notification token ${ req.params.token } not found`)
throw new ModelError('E_NOT_FOUND', `Notification token ${ req.params.token } not found`)
}
return this.app.services.PermissionsService.sanitizeResult(req, notification)
})
Expand Down Expand Up @@ -80,7 +81,7 @@ export class NotificationController extends Controller {
Notification.resolve(req.params.notification)
.then(notification => {
if (!notification) {
throw new Error(`Notification ${ req.params.notification } not found`)
throw new ModelError('E_NOT_FOUND', `Notification ${ req.params.notification } not found`)
}
return this.app.services.PermissionsService.sanitizeResult(req, notification)
})
Expand All @@ -103,7 +104,7 @@ export class NotificationController extends Controller {
const limit = Math.max(0, req.query.limit || 10)
const offset = Math.max(0, req.query.offset || 0)
const sort = req.query.sort || [['created_at', 'DESC']]
const where = res.jsonCritera(req.query.where)
const where = req.jsonCriteria(req.query.where)

Notification.findAndCountDefault({
where: where,
Expand All @@ -130,8 +131,7 @@ export class NotificationController extends Controller {
* @param res
*/
userNotifications(req, res) {
const orm = this.app.models
const Notification = orm['Notification']
const Notification = this.app.models['Notification']
const limit = Math.max(0, req.query.limit || 10)
const offset = Math.max(0, req.query.offset || 0)
const sort = req.query.sort || [['created_at', 'DESC']]
Expand All @@ -154,7 +154,7 @@ export class NotificationController extends Controller {
Notification.findAndCountDefault({
include: [
{
model: this.app.models['User'],
model: this.app.models['User'].resolver.sequelizeModel,
as: 'users',
where: {
id: id
Expand Down
9 changes: 8 additions & 1 deletion lib/api/models/ItemNotification.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FabrixModel as Model } from '@fabrix/fabrix/dist/common'

import { SequelizeResolver } from '@fabrix/spool-sequelize'
/**
* @module ItemNotification
* @description Item Notification
Expand Down Expand Up @@ -41,6 +41,13 @@ export class ItemNotification extends Model {
}
}

/**
* Sequelize Resolver
*/
public static get resolver() {
return SequelizeResolver
}

/**
* Associate the Model
* @param models
Expand Down
Loading

0 comments on commit 9e8757f

Please sign in to comment.