This repository was archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Badge types #64
Open
daytonn
wants to merge
4
commits into
master
Choose a base branch
from
badge-types
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Badge types #64
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,47 @@ | ||
| const util = require('util'); | ||
| const db = require('../lib/db'); | ||
| const validation = require('../lib/validation'); | ||
|
|
||
| const makeValidator = validation.makeValidator; | ||
| const optional = validation.optional; | ||
| const required = validation.required; | ||
|
|
||
| const BadgeTypes = db.table('badgeTypes', { | ||
| fields: [ | ||
| 'id', | ||
| 'name', | ||
| 'programId', | ||
| 'issuerId', | ||
| 'systemId' | ||
| ], | ||
| relationships: { | ||
| system: { | ||
| type: 'hasOne', | ||
| local: 'systemId', | ||
| foreign: { table: 'systems', key: 'id' }, | ||
| optional: true, | ||
| }, | ||
| issuer: { | ||
| type: 'hasOne', | ||
| local: 'issuerId', | ||
| foreign: { table: 'issuers', key: 'id' }, | ||
| optional: true, | ||
| }, | ||
| program: { | ||
| type: 'hasOne', | ||
| local: 'programId', | ||
| foreign: { table: 'programs', key: 'id' }, | ||
| optional: true, | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| BadgeTypes.validateRow = makeValidator({ | ||
| id: optional('isInt'), | ||
| name: required('len', 1, 255), | ||
| issuerId: optional('isInt'), | ||
| programId: optional('isInt'), | ||
| systemId: optional('isInt') | ||
| }); | ||
|
|
||
| exports = module.exports = BadgeTypes; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
| #!/usr/bin/env bash | ||
| if [ -z "$DB_USER" ] || [ -z "$DB_NAME" ]; then | ||
| echo "You must have your environment configured for the database" | ||
| echo "example:" | ||
| echo " export DB_NAME=badgekitapi" | ||
| echo " export DB_USER=root" | ||
| echo " export DB_PASSWORD=mypassword" | ||
| else | ||
| if [ -z "$DB_PASSWORD" ]; then | ||
| mysql -u $DB_USER $DB_NAME < schema.sql | ||
| else | ||
| mysql -u $DB_USER "-p$DB_PASSWORD" $DB_NAME < schema.sql | ||
| fi | ||
| fi |
This file contains hidden or 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,8 @@ | ||
| #!/usr/bin/env bash | ||
| source .test-env | ||
| if [ -n "$1" ]; then | ||
| ./node_modules/.bin/tap test/"$1".test.js | ||
| else | ||
| npm test | ||
| fi | ||
| source .env |
This file contains hidden or 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,28 @@ | ||
| const test = require('tap').test; | ||
| const BadgeTypes = require('../app/models/badge-type'); | ||
|
|
||
| const closeDb = BadgeTypes.db.close.bind(BadgeTypes.db); | ||
|
|
||
| test('validating rows', function(t) { | ||
| var errors; | ||
|
|
||
| errors = BadgeTypes.validateRow({ | ||
| id: 'foo', | ||
| name: null, | ||
| issuerId: 'foo', | ||
| programId: 'foo', | ||
| systemId: 'foo' | ||
| }); | ||
| t.same(errors.length, 5); | ||
|
|
||
| errors = BadgeTypes.validateRow({ | ||
| id: 1, | ||
| name: 'SomeType', | ||
| issuerId: 1, | ||
| programId: 1, | ||
| systemId: 1 | ||
| }); | ||
| t.same(errors.length, 0); | ||
|
|
||
| closeDb(); t.end(); | ||
| }); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the errors you're getting during testing are actually because nothing is ever actually requiring the ./badge-type model during those tests, so the badge model gets confused because it has a relationship to a 'badgeTypes' table that never gets defined. Adding a
line here will fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, it had to be something stupid. I'm spoiled by rails. Make a model, voila it's available ;)