Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Add method for getting badge claim codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianloveswords committed Apr 23, 2013
1 parent a4c2e33 commit 4e47ef5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 7 additions & 6 deletions models/badge.js
Expand Up @@ -293,12 +293,6 @@ Badge.prototype.generateClaimCodes = function generateClaimCodes(options, callba
});
};

/**
* Find an claim code by name
*
* @param {String} code
* @return {Object|Null}
*/

Badge.prototype.getClaimCode = function getClaimCode(code) {
const codes = this.claimCodes;
Expand All @@ -311,6 +305,13 @@ Badge.prototype.getClaimCode = function getClaimCode(code) {
return null;
};

Badge.prototype.getClaimCodes = function getClaimCodes() {
const codes = this.claimCodes;
return codes.map(function (entry) {
return entry.code;
});
};

/**
* Whether or not an claim code is claimed
*
Expand Down
9 changes: 8 additions & 1 deletion tests/badge-model.test.js
Expand Up @@ -231,14 +231,21 @@ test.applyFixtures(fixtures, function () {
});
});

test('Badge.hasClaimCode', function (t) {
test('Badge#hasClaimCode', function (t) {
const badge = fixtures['offline-badge'];
const code = 'will-claim';
t.same(badge.hasClaimCode(code), true);
t.same(badge.hasClaimCode('nopeniopenope'), false);
t.end();
});

test('Badge#getClaimCodes', function (t) {
const badge = fixtures['offline-badge'];
const expect = [ 'already-claimed', 'never-claim', 'will-claim', 'remove-claim' ];
t.same(badge.getClaimCodes(), expect);
t.end();
});

test('Badge#addClaimCodes', function (t) {
const badge = fixtures['offline-badge'];
const codes = ['lethargic-hummingbird', 'woeful-turtle'];
Expand Down

0 comments on commit 4e47ef5

Please sign in to comment.