This repository has been archived by the owner on Mar 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jamesrichford-issue/150'
- Loading branch information
Showing
2 changed files
with
52 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const QueueName = require('../lib/validation/queue/QueueName'), | ||
AError = require('../lib/core/AzuriteError') | ||
ErrorCodes = require('../lib/core/ErrorCodes') | ||
expect = require('chai').expect; | ||
|
||
describe('validation', () => { | ||
describe('QueueName', () => { | ||
const createQueueNameRequest = (queueName) => { return { request: { queueName } } }; | ||
|
||
it('should throw out of range if name is less than three characters', () => { | ||
expect(() => QueueName.validate(createQueueNameRequest(''))).to.throw(AError, ErrorCodes.OutOfRangeInput); | ||
expect(() => QueueName.validate(createQueueNameRequest('a'))).to.throw(AError, ErrorCodes.OutOfRangeInput); | ||
expect(() => QueueName.validate(createQueueNameRequest('aa'))).to.throw(AError, ErrorCodes.OutOfRangeInput); | ||
expect(() => QueueName.validate(createQueueNameRequest('aaa'))).not.to.throw(); | ||
}); | ||
|
||
it('should throw out of range if name is greater than sixty three characters', () => { | ||
const sixtyThreeCharacterStringName = '012345678901234567890123456789012345678901234567890123456789012'; | ||
|
||
expect(() => QueueName.validate(createQueueNameRequest(sixtyThreeCharacterStringName))).not.to.throw(); | ||
expect(() => QueueName.validate(createQueueNameRequest(sixtyThreeCharacterStringName + '3'))).to.throw(AError, ErrorCodes.OutOfRangeInput); | ||
expect(() => QueueName.validate(createQueueNameRequest(sixtyThreeCharacterStringName + '34'))).to.throw(AError, ErrorCodes.OutOfRangeInput); | ||
}); | ||
|
||
it('should throw invalid input if name starts with a dash', () => { | ||
expect(() => QueueName.validate(createQueueNameRequest("-queue"))).to.throw(AError, ErrorCodes.InvalidInput); | ||
expect(() => QueueName.validate(createQueueNameRequest("-queue-name"))).to.throw(AError, ErrorCodes.InvalidInput); | ||
}); | ||
|
||
it('should throw invalid input if name ends with a dash', () => { | ||
expect(() => QueueName.validate(createQueueNameRequest("queue-"))).to.throw(AError, ErrorCodes.InvalidInput); | ||
expect(() => QueueName.validate(createQueueNameRequest("queue-name-"))).to.throw(AError, ErrorCodes.InvalidInput); | ||
}); | ||
|
||
it('should throw invalid input if contians two consecutive dashes', () => { | ||
expect(() => QueueName.validate(createQueueNameRequest("queue--name"))).to.throw(AError, ErrorCodes.InvalidInput); | ||
}); | ||
|
||
it('should throw invalid input if contians anything except alphanumeric characters and dashes', () => { | ||
expect(() => QueueName.validate(createQueueNameRequest("queue-name"))).not.to.throw(); | ||
expect(() => QueueName.validate(createQueueNameRequest("queue1"))).not.to.throw(); | ||
expect(() => QueueName.validate(createQueueNameRequest("QUEUE-name-1"))).not.to.throw(); | ||
expect(() => QueueName.validate(createQueueNameRequest("queue_name"))).to.throw(AError, ErrorCodes.InvalidInput); | ||
expect(() => QueueName.validate(createQueueNameRequest("queue name"))).to.throw(AError, ErrorCodes.InvalidInput); | ||
expect(() => QueueName.validate(createQueueNameRequest("queue~name"))).to.throw(AError, ErrorCodes.InvalidInput); | ||
expect(() => QueueName.validate(createQueueNameRequest("queue@name"))).to.throw(AError, ErrorCodes.InvalidInput); | ||
expect(() => QueueName.validate(createQueueNameRequest("queue:name"))).to.throw(AError, ErrorCodes.InvalidInput); | ||
}); | ||
}); | ||
}); |