Permalink
Browse files

Test image maximum size validation.

  • Loading branch information...
1 parent cc4bccb commit 988c43b90fdcadad917d92008c789d9300f93d19 @brianloveswords brianloveswords committed Oct 10, 2012
Showing with 22 additions and 4 deletions.
  1. +22 −4 test/badge-model.test.js
View
@@ -63,26 +63,44 @@ test.applyFixtures(fixtures, function () {
});
});
+ test('Badge#validate: image too big', function (t) {
+ var errorKeys;
+ var badge = validBadge();
+ var length = 257 * 1024
+ badge.image = Buffer(length);
+ badge.validate(function (err) {
+ t.ok(err, 'should have errors');
+ errorKeys = Object.keys(err.errors);
+ t.same(errorKeys, ['image'], 'should only have one error');
+ t.same(err.errors['image'].type, 'maxLength', 'should be a maxLength error');
+ t.end();
+ });
+ });
+
test('Badge#validate: name too long', function (t) {
+ var errorKeys;
var length = 128;
var badge = validBadge();
badge.name = test.randomstring(length + 1);
badge.validate(function (err, results) {
- var errorKeys = Object.keys(err.errors);
+ t.ok(err, 'should have errors');
+ errorKeys = Object.keys(err.errors);
t.same(errorKeys, ['name'], 'should only have one error');
- t.same(err.errors.name.type, 'maxLength', 'should be a maxLength error');
+ t.same(err.errors['name'].type, 'maxLength', 'should be a maxLength error');
t.end();
});
});
test('Badge#validate: description too long', function (t) {
+ var errorKeys;
var length = 128;
var badge = validBadge();
badge.description = test.randomstring(length + 1);
badge.validate(function (err, results) {
- var errorKeys = Object.keys(err.errors);
+ t.ok(err, 'should have errors');
+ errorKeys = Object.keys(err.errors);
t.same(errorKeys, ['description'], 'should only have one error');
- t.same(err.errors.description.type, 'maxLength', 'should be a maxLength error');
+ t.same(err.errors['description'].type, 'maxLength', 'should be a maxLength error');
t.end();
});
});

0 comments on commit 988c43b

Please sign in to comment.