Skip to content

Commit

Permalink
Merge branch 'TheHollidayInn-api-v3-challenge-shortname-validation' i…
Browse files Browse the repository at this point in the history
…nto api-v3
  • Loading branch information
crookedneighbor committed May 23, 2016
2 parents 7d45223 + 8cf4f9f commit c5215e8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion common/locales/en/challenge.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@
"userTasksNoChallengeId": "When \"tasksOwner\" is \"user\" \"challengeId\" can't be passed.",
"onlyChalLeaderEditTasks": "Tasks belonging to a challenge can only be edited by the leader.",
"userAlreadyInChallenge": "User is already participating in this challenge.",
"cantOnlyUnlinkChalTask": "Only broken challenges tasks can be unlinked."
"cantOnlyUnlinkChalTask": "Only broken challenges tasks can be unlinked.",
"shortNameTooShort": "Short Name must have at least 3 characters."
}
22 changes: 11 additions & 11 deletions test/api/v3/integration/challenges/POST-challenges.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('POST /challenges', () => {
let chal = await groupMember.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC',
shortName: 'TC Label',
});

expect(chal.leader).to.eql({
Expand All @@ -131,7 +131,7 @@ describe('POST /challenges', () => {
await groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC',
shortName: 'TC Label',
prize: 0,
});

Expand All @@ -143,7 +143,7 @@ describe('POST /challenges', () => {
await expect(groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC',
shortName: 'TC Label',
prize: 20,
})).to.eventually.be.rejected.and.eql({
code: 401,
Expand All @@ -160,7 +160,7 @@ describe('POST /challenges', () => {
await groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC',
shortName: 'TC Label',
prize,
});

Expand All @@ -175,7 +175,7 @@ describe('POST /challenges', () => {
await groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC',
shortName: 'TC Label',
prize,
});

Expand All @@ -191,7 +191,7 @@ describe('POST /challenges', () => {
await groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC',
shortName: 'TC Label',
prize,
});

Expand All @@ -205,7 +205,7 @@ describe('POST /challenges', () => {
await groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC',
shortName: 'TC Label',
});

await expect(group.sync()).to.eventually.have.property('challengeCount', oldChallengeCount + 1);
Expand All @@ -221,7 +221,7 @@ describe('POST /challenges', () => {
let challenge = await groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC',
shortName: 'TC Label',
official: true,
});

Expand All @@ -232,7 +232,7 @@ describe('POST /challenges', () => {
let challenge = await groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC',
shortName: 'TC Label',
official: true,
});

Expand Down Expand Up @@ -265,7 +265,7 @@ describe('POST /challenges', () => {

it('sets all properites of the challenge as passed', async () => {
let name = 'Test Challenge';
let shortName = 'TC';
let shortName = 'TC Label';
let description = 'Test Description';
let prize = 4;

Expand Down Expand Up @@ -299,7 +299,7 @@ describe('POST /challenges', () => {
let challenge = await groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC',
shortName: 'TC Label',
});

await expect(groupLeader.sync()).to.eventually.have.property('challenges').to.include(challenge._id);
Expand Down
7 changes: 7 additions & 0 deletions test/spec/controllers/challengesCtrlSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ describe('Challenges Controller', function() {
it("opens an alert box if challenge.group is not specified", function() {
var challenge = specHelper.newChallenge({
name: 'Challenge without a group',
shortName: 'chal without group',
group: null
});

Expand All @@ -356,6 +357,7 @@ describe('Challenges Controller', function() {
it("opens an alert box if isNew and user does not have enough gems", function() {
var challenge = specHelper.newChallenge({
name: 'Challenge without enough gems',
shortName: 'chal without gem',
prize: 5
});

Expand All @@ -372,6 +374,7 @@ describe('Challenges Controller', function() {
var challenge = specHelper.newChallenge({
_id: 'challenge-has-id-so-its-not-new',
name: 'Challenge without enough gems',
shortName: 'chal without gem',
prize: 5,
});

Expand All @@ -385,6 +388,7 @@ describe('Challenges Controller', function() {
it("saves the challenge if user has enough gems and challenge is new", function() {
var challenge = specHelper.newChallenge({
name: 'Challenge without enough gems',
shortName: 'chal without gem',
prize: 5,
});

Expand All @@ -400,6 +404,7 @@ describe('Challenges Controller', function() {

var challenge = specHelper.newChallenge({
name: 'Challenge',
shortName: 'chal',
});

setTimeout(function() {
Expand All @@ -419,6 +424,7 @@ describe('Challenges Controller', function() {

it('saves new challenge and syncs User', function(done) {
var challenge = specHelper.newChallenge();
challenge.shortName = 'chal';

setTimeout(function() {
expect(User.sync).to.be.calledOnce;
Expand All @@ -432,6 +438,7 @@ describe('Challenges Controller', function() {
sinon.stub(notification, 'text');

var challenge = specHelper.newChallenge();
challenge.shortName = 'chal';

setTimeout(function() {
expect(notification.text).to.be.calledOnce;
Expand Down
2 changes: 2 additions & 0 deletions website/client/js/controllers/challengesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
$scope.save = function(challenge) {
if (!challenge.group) return alert(window.env.t('selectGroup'));

if (!challenge.shortName || challenge.shortName.length < 3) return alert(window.env.t('shortNameTooShort'));

var isNew = !challenge._id;

if(isNew && challenge.prize > $scope.maxPrize) {
Expand Down
2 changes: 1 addition & 1 deletion website/server/models/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let Schema = mongoose.Schema;

let schema = new Schema({
name: {type: String, required: true},
shortName: {type: String, required: true},
shortName: {type: String, required: true, minlength: 3},
description: String,
official: {type: Boolean, default: false},
tasksOrder: {
Expand Down
2 changes: 1 addition & 1 deletion website/views/options/social/challenges.jade
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ script(type='text/ng-template', id='partials/options.social.challenges.html')

.row
.form-group.col-md-6.col-sm-12
input.form-control(type='text', minlength="3",
input.form-control(type='text',
ng-model='newChallenge.shortName', placeholder=env.t('challengeTag'), required
ng-disabled='insufficientGemsForTavernChallenge()')
|&nbsp;
Expand Down

0 comments on commit c5215e8

Please sign in to comment.