Merge branch 'TheHollidayInn-api-v3-challenge-shortname-validation' into api-v3

This commit is contained in:
Blade Barringer
2016-05-22 20:58:23 -05:00
6 changed files with 24 additions and 14 deletions

View File

@@ -78,5 +78,6 @@
"userTasksNoChallengeId": "When \"tasksOwner\" is \"user\" \"challengeId\" can't be passed.", "userTasksNoChallengeId": "When \"tasksOwner\" is \"user\" \"challengeId\" can't be passed.",
"onlyChalLeaderEditTasks": "Tasks belonging to a challenge can only be edited by the leader.", "onlyChalLeaderEditTasks": "Tasks belonging to a challenge can only be edited by the leader.",
"userAlreadyInChallenge": "User is already participating in this challenge.", "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."
} }

View File

@@ -115,7 +115,7 @@ describe('POST /challenges', () => {
let chal = await groupMember.post('/challenges', { let chal = await groupMember.post('/challenges', {
group: group._id, group: group._id,
name: 'Test Challenge', name: 'Test Challenge',
shortName: 'TC', shortName: 'TC Label',
}); });
expect(chal.leader).to.eql({ expect(chal.leader).to.eql({
@@ -131,7 +131,7 @@ describe('POST /challenges', () => {
await groupLeader.post('/challenges', { await groupLeader.post('/challenges', {
group: group._id, group: group._id,
name: 'Test Challenge', name: 'Test Challenge',
shortName: 'TC', shortName: 'TC Label',
prize: 0, prize: 0,
}); });
@@ -143,7 +143,7 @@ describe('POST /challenges', () => {
await expect(groupLeader.post('/challenges', { await expect(groupLeader.post('/challenges', {
group: group._id, group: group._id,
name: 'Test Challenge', name: 'Test Challenge',
shortName: 'TC', shortName: 'TC Label',
prize: 20, prize: 20,
})).to.eventually.be.rejected.and.eql({ })).to.eventually.be.rejected.and.eql({
code: 401, code: 401,
@@ -160,7 +160,7 @@ describe('POST /challenges', () => {
await groupLeader.post('/challenges', { await groupLeader.post('/challenges', {
group: group._id, group: group._id,
name: 'Test Challenge', name: 'Test Challenge',
shortName: 'TC', shortName: 'TC Label',
prize, prize,
}); });
@@ -175,7 +175,7 @@ describe('POST /challenges', () => {
await groupLeader.post('/challenges', { await groupLeader.post('/challenges', {
group: group._id, group: group._id,
name: 'Test Challenge', name: 'Test Challenge',
shortName: 'TC', shortName: 'TC Label',
prize, prize,
}); });
@@ -191,7 +191,7 @@ describe('POST /challenges', () => {
await groupLeader.post('/challenges', { await groupLeader.post('/challenges', {
group: group._id, group: group._id,
name: 'Test Challenge', name: 'Test Challenge',
shortName: 'TC', shortName: 'TC Label',
prize, prize,
}); });
@@ -205,7 +205,7 @@ describe('POST /challenges', () => {
await groupLeader.post('/challenges', { await groupLeader.post('/challenges', {
group: group._id, group: group._id,
name: 'Test Challenge', name: 'Test Challenge',
shortName: 'TC', shortName: 'TC Label',
}); });
await expect(group.sync()).to.eventually.have.property('challengeCount', oldChallengeCount + 1); await expect(group.sync()).to.eventually.have.property('challengeCount', oldChallengeCount + 1);
@@ -221,7 +221,7 @@ describe('POST /challenges', () => {
let challenge = await groupLeader.post('/challenges', { let challenge = await groupLeader.post('/challenges', {
group: group._id, group: group._id,
name: 'Test Challenge', name: 'Test Challenge',
shortName: 'TC', shortName: 'TC Label',
official: true, official: true,
}); });
@@ -232,7 +232,7 @@ describe('POST /challenges', () => {
let challenge = await groupLeader.post('/challenges', { let challenge = await groupLeader.post('/challenges', {
group: group._id, group: group._id,
name: 'Test Challenge', name: 'Test Challenge',
shortName: 'TC', shortName: 'TC Label',
official: true, official: true,
}); });
@@ -265,7 +265,7 @@ describe('POST /challenges', () => {
it('sets all properites of the challenge as passed', async () => { it('sets all properites of the challenge as passed', async () => {
let name = 'Test Challenge'; let name = 'Test Challenge';
let shortName = 'TC'; let shortName = 'TC Label';
let description = 'Test Description'; let description = 'Test Description';
let prize = 4; let prize = 4;
@@ -299,7 +299,7 @@ describe('POST /challenges', () => {
let challenge = await groupLeader.post('/challenges', { let challenge = await groupLeader.post('/challenges', {
group: group._id, group: group._id,
name: 'Test Challenge', name: 'Test Challenge',
shortName: 'TC', shortName: 'TC Label',
}); });
await expect(groupLeader.sync()).to.eventually.have.property('challenges').to.include(challenge._id); await expect(groupLeader.sync()).to.eventually.have.property('challenges').to.include(challenge._id);

View File

@@ -344,6 +344,7 @@ describe('Challenges Controller', function() {
it("opens an alert box if challenge.group is not specified", function() { it("opens an alert box if challenge.group is not specified", function() {
var challenge = specHelper.newChallenge({ var challenge = specHelper.newChallenge({
name: 'Challenge without a group', name: 'Challenge without a group',
shortName: 'chal without group',
group: null group: null
}); });
@@ -356,6 +357,7 @@ describe('Challenges Controller', function() {
it("opens an alert box if isNew and user does not have enough gems", function() { it("opens an alert box if isNew and user does not have enough gems", function() {
var challenge = specHelper.newChallenge({ var challenge = specHelper.newChallenge({
name: 'Challenge without enough gems', name: 'Challenge without enough gems',
shortName: 'chal without gem',
prize: 5 prize: 5
}); });
@@ -372,6 +374,7 @@ describe('Challenges Controller', function() {
var challenge = specHelper.newChallenge({ var challenge = specHelper.newChallenge({
_id: 'challenge-has-id-so-its-not-new', _id: 'challenge-has-id-so-its-not-new',
name: 'Challenge without enough gems', name: 'Challenge without enough gems',
shortName: 'chal without gem',
prize: 5, prize: 5,
}); });
@@ -385,6 +388,7 @@ describe('Challenges Controller', function() {
it("saves the challenge if user has enough gems and challenge is new", function() { it("saves the challenge if user has enough gems and challenge is new", function() {
var challenge = specHelper.newChallenge({ var challenge = specHelper.newChallenge({
name: 'Challenge without enough gems', name: 'Challenge without enough gems',
shortName: 'chal without gem',
prize: 5, prize: 5,
}); });
@@ -400,6 +404,7 @@ describe('Challenges Controller', function() {
var challenge = specHelper.newChallenge({ var challenge = specHelper.newChallenge({
name: 'Challenge', name: 'Challenge',
shortName: 'chal',
}); });
setTimeout(function() { setTimeout(function() {
@@ -419,6 +424,7 @@ describe('Challenges Controller', function() {
it('saves new challenge and syncs User', function(done) { it('saves new challenge and syncs User', function(done) {
var challenge = specHelper.newChallenge(); var challenge = specHelper.newChallenge();
challenge.shortName = 'chal';
setTimeout(function() { setTimeout(function() {
expect(User.sync).to.be.calledOnce; expect(User.sync).to.be.calledOnce;
@@ -432,6 +438,7 @@ describe('Challenges Controller', function() {
sinon.stub(notification, 'text'); sinon.stub(notification, 'text');
var challenge = specHelper.newChallenge(); var challenge = specHelper.newChallenge();
challenge.shortName = 'chal';
setTimeout(function() { setTimeout(function() {
expect(notification.text).to.be.calledOnce; expect(notification.text).to.be.calledOnce;

View File

@@ -120,6 +120,8 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
$scope.save = function(challenge) { $scope.save = function(challenge) {
if (!challenge.group) return alert(window.env.t('selectGroup')); 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; var isNew = !challenge._id;
if(isNew && challenge.prize > $scope.maxPrize) { if(isNew && challenge.prize > $scope.maxPrize) {

View File

@@ -19,7 +19,7 @@ let Schema = mongoose.Schema;
let schema = new Schema({ let schema = new Schema({
name: {type: String, required: true}, name: {type: String, required: true},
shortName: {type: String, required: true}, shortName: {type: String, required: true, minlength: 3},
description: String, description: String,
official: {type: Boolean, default: false}, official: {type: Boolean, default: false},
tasksOrder: { tasksOrder: {

View File

@@ -145,7 +145,7 @@ script(type='text/ng-template', id='partials/options.social.challenges.html')
.row .row
.form-group.col-md-6.col-sm-12 .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-model='newChallenge.shortName', placeholder=env.t('challengeTag'), required
ng-disabled='insufficientGemsForTavernChallenge()') ng-disabled='insufficientGemsForTavernChallenge()')
|&nbsp; |&nbsp;