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

Commit

Permalink
Rename method getRecommendations to getSimilar
Browse files Browse the repository at this point in the history
The method on the Badge model `getRecommendations` was actually getting
similar badges based on the category of a badge. I'm about to implement
the *actual* `getRecommendations` function, which is based on a user's
earned badges history, as well as a handful of other rules.
  • Loading branch information
brianloveswords committed Jun 2, 2013
1 parent b7d5562 commit e7dfd0d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion models/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ Badge.prototype.getRubricItems = function() {
: [];
};

Badge.prototype.getRecommendations = function (email, callback) {
Badge.prototype.getSimilar = function (email, callback) {
const thisShortname = this.shortname;
if (typeof email == 'function')
callback = email, email = null;
Expand Down
4 changes: 2 additions & 2 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ function parseLimit(userLimit) {
return userLimit;
}

exports.recommendations = function recommendations(req, res, next) {
exports.similarBadges = function similarBadges(req, res, next) {
const badge = req.badge;
const email = req.query.email;
const limit = parseLimit(req.query.limit, 10);

badge.getRecommendations(email, function (err, badges) {
badge.getSimilar(email, function (err, badges) {
if (err)
return res.json(500, { status: 'error', error: err });

Expand Down
6 changes: 5 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,13 @@ exports.define = function defineRoutes(app) {
findBadgeByParamShortname
], api.badge);

// 'similar' aliased to 'recommendations'
app.get('/v2/badge/:shortname/similar', [
findBadgeByParamShortname
], api.similarBadges);
app.get('/v2/badge/:shortname/recommendations', [
findBadgeByParamShortname
], api.recommendations);
], api.similarBadges);

app.get('/v2/unclaimed', [
api.auth()
Expand Down
4 changes: 2 additions & 2 deletions tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ test.applyFixtures(badgeFixtures, function(fx) {

test('api can give badge recommendations', function(t) {
conmock({
handler: api.recommendations,
handler: api.similarBadges,
request: {
badge: fx['science1']
}
Expand All @@ -316,7 +316,7 @@ test.applyFixtures(badgeFixtures, function(fx) {

test('api can give badge recommendations with a limit', function(t) {
conmock({
handler: api.recommendations,
handler: api.similarBadges,
request: {
badge: fx['science1'],
query: { limit: '2' },
Expand Down
4 changes: 2 additions & 2 deletions tests/badge-recommendations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test.applyFixtures({

test('Recommendation, no user', function (t) {
const pureScience = fx['pure-science'];
pureScience.getRecommendations(function (err, badges) {
pureScience.getSimilar(function (err, badges) {
const shortnames = badges.map(util.prop('shortname'));
const hasMath = shortnames.some(has('pure-math'));
const hasSelf = shortnames.some(has('pure-science'));
Expand All @@ -59,7 +59,7 @@ test.applyFixtures({

test('Recommendation, with user', function (t) {
const pureScience = fx['pure-science'];
pureScience.getRecommendations(TESTUSER, function (err, badges) {
pureScience.getSimilar(TESTUSER, function (err, badges) {
const names = badges.map(util.prop('shortname'));
const hasMath = badges.some(has('pure-math'));
const hasEarned = badges.some(has('earned'));
Expand Down

0 comments on commit e7dfd0d

Please sign in to comment.