1 | const QueueName = require('../lib/validation/queue/QueueName'),
|
2 | AError = require('../lib/core/AzuriteError')
|
3 | ErrorCodes = require('../lib/core/ErrorCodes')
|
4 | expect = require('chai').expect;
|
5 |
|
6 | describe('validation', () => {
|
7 | describe('QueueName', () => {
|
8 | const createQueueNameRequest = (queueName) => { return { request: { queueName } } };
|
9 |
|
10 | it('should throw out of range if name is less than three characters', () => {
|
11 | expect(() => QueueName.validate(createQueueNameRequest(''))).to.throw(AError, ErrorCodes.OutOfRangeInput);
|
12 | expect(() => QueueName.validate(createQueueNameRequest('a'))).to.throw(AError, ErrorCodes.OutOfRangeInput);
|
13 | expect(() => QueueName.validate(createQueueNameRequest('aa'))).to.throw(AError, ErrorCodes.OutOfRangeInput);
|
14 | expect(() => QueueName.validate(createQueueNameRequest('aaa'))).not.to.throw();
|
15 | });
|
16 |
|
17 | it('should throw out of range if name is greater than sixty three characters', () => {
|
18 | const sixtyThreeCharacterStringName = '012345678901234567890123456789012345678901234567890123456789012';
|
19 |
|
20 | expect(() => QueueName.validate(createQueueNameRequest(sixtyThreeCharacterStringName))).not.to.throw();
|
21 | expect(() => QueueName.validate(createQueueNameRequest(sixtyThreeCharacterStringName + '3'))).to.throw(AError, ErrorCodes.OutOfRangeInput);
|
22 | expect(() => QueueName.validate(createQueueNameRequest(sixtyThreeCharacterStringName + '34'))).to.throw(AError, ErrorCodes.OutOfRangeInput);
|
23 | });
|
24 |
|
25 | it('should throw invalid input if name starts with a dash', () => {
|
26 | expect(() => QueueName.validate(createQueueNameRequest("-queue"))).to.throw(AError, ErrorCodes.InvalidInput);
|
27 | expect(() => QueueName.validate(createQueueNameRequest("-queue-name"))).to.throw(AError, ErrorCodes.InvalidInput);
|
28 | });
|
29 |
|
30 | it('should throw invalid input if name ends with a dash', () => {
|
31 | expect(() => QueueName.validate(createQueueNameRequest("queue-"))).to.throw(AError, ErrorCodes.InvalidInput);
|
32 | expect(() => QueueName.validate(createQueueNameRequest("queue-name-"))).to.throw(AError, ErrorCodes.InvalidInput);
|
33 | });
|
34 |
|
35 | it('should throw invalid input if contians two consecutive dashes', () => {
|
36 | expect(() => QueueName.validate(createQueueNameRequest("queue--name"))).to.throw(AError, ErrorCodes.InvalidInput);
|
37 | });
|
38 |
|
39 | it('should throw invalid input if contians anything except alphanumeric characters and dashes', () => {
|
40 | expect(() => QueueName.validate(createQueueNameRequest("queue-name"))).not.to.throw();
|
41 | expect(() => QueueName.validate(createQueueNameRequest("queue1"))).not.to.throw();
|
42 | expect(() => QueueName.validate(createQueueNameRequest("QUEUE-name-1"))).not.to.throw();
|
43 | expect(() => QueueName.validate(createQueueNameRequest("queue_name"))).to.throw(AError, ErrorCodes.InvalidInput);
|
44 | expect(() => QueueName.validate(createQueueNameRequest("queue name"))).to.throw(AError, ErrorCodes.InvalidInput);
|
45 | expect(() => QueueName.validate(createQueueNameRequest("queue~name"))).to.throw(AError, ErrorCodes.InvalidInput);
|
46 | expect(() => QueueName.validate(createQueueNameRequest("queue@name"))).to.throw(AError, ErrorCodes.InvalidInput);
|
47 | expect(() => QueueName.validate(createQueueNameRequest("queue:name"))).to.throw(AError, ErrorCodes.InvalidInput);
|
48 | });
|
49 | });
|
50 | });
|