[Groonga-commit] groonga/gcs [master] Add tests for validation error of CreateDomain action

アーカイブの一覧に戻る

YUKI Hiroshi null+****@clear*****
Mon Nov 5 15:43:37 JST 2012


YUKI Hiroshi	2012-11-05 15:43:37 +0900 (Mon, 05 Nov 2012)

  New Revision: ac5437686d59cabe991399f6200c9efd8aa53187
  https://github.com/groonga/gcs/commit/ac5437686d59cabe991399f6200c9efd8aa53187

  Log:
    Add tests for validation error of CreateDomain action

  Modified files:
    test/api-configuration.test.js
    test/xml-responses.js

  Modified: test/api-configuration.test.js (+78 -0)
===================================================================
--- test/api-configuration.test.js    2012-11-05 15:29:34 +0900 (29a1ee0)
+++ test/api-configuration.test.js    2012-11-05 15:43:37 +0900 (ebce220)
@@ -52,6 +52,24 @@ suite('Configuration API', function() {
     assert.deepEqual(status, expectedStatus);
   }
 
+  function assertValidationErrorResponse(expectedMessage, response) {
+    assert.deepEqual(response.pattern,
+                     { statusCode: 400,
+                       body: xmlResponses.TYPED_ERROR_RESPONSE });
+    var expectedResponse = {
+          type: 'Sender',
+          code: 'ValidationError',
+          message: expectedMessage
+        };
+    var error = response.body.Response.Errors.Error;
+    var actualResponse = {
+          type: error.Type,
+          code: error.Code,
+          message: error.Message
+        };
+    assert.deepEqual(actualResponse, expectedResponse);
+  }
+
   suite('domain operations', function() {
     setup(commonSetup);
     teardown(commonTeardown);
@@ -80,6 +98,66 @@ suite('Configuration API', function() {
         });
     });
 
+    test('Action=CreateDomain with too short (one character) domain name', function(done) {
+      utils
+        .get('/?DomainName=a&Action=CreateDomain&Version=2011-02-01')
+        .next(function(response) {
+          assertValidationErrorResponse(
+            '2 validation errors detected: ' +
+              'Value \'a\' at \'domainName\' failed to satisfy constraint: ' +
+                'Member must satisfy regular expression pattern: ' +
+                  Domain.VALID_NAME_PATTERN + '; ' +
+              'Value \'a\' at \'domainName\' failed to satisfy constraint: ' +
+                'Member must have length greater than or equal to ' +
+                  Domain.MINIMUM_NAME_LENGTH,
+            response
+          );
+          done();
+        })
+        .error(function(error) {
+          done(error);
+        });
+    });
+
+    test('Action=CreateDomain with too short (two characters) domain name', function(done) {
+      utils
+        .get('/?DomainName=va&Action=CreateDomain&Version=2011-02-01')
+        .next(function(response) {
+          assertValidationErrorResponse(
+            '1 validation error detected: ' +
+              'Value \'va\' at \'domainName\' failed to satisfy constraint: ' +
+                'Member must have length greater than or equal to ' +
+                  Domain.MINIMUM_NAME_LENGTH,
+            response
+          );
+          done();
+        })
+        .error(function(error) {
+          done(error);
+        });
+    });
+
+    test('Action=CreateDomain without domain name', function(done) {
+      utils
+        .get('/?DomainName=&Action=CreateDomain&Version=2011-02-01')
+        .next(function(response) {
+          assertValidationErrorResponse(
+            '2 validation errors detected: ' +
+              'Value \'\' at \'domainName\' failed to satisfy constraint: ' +
+                'Member must satisfy regular expression pattern: ' +
+                  Domain.VALID_NAME_PATTERN + '; ' +
+              'Value \'\' at \'domainName\' failed to satisfy constraint: ' +
+                'Member must have length greater than or equal to ' +
+                  Domain.MINIMUM_NAME_LENGTH,
+            response
+          );
+          done();
+        })
+        .error(function(error) {
+          done(error);
+        });
+    });
+
     test('Action=DeleteDomain', function(done) {
       var domain;
       utils

  Modified: test/xml-responses.js (+14 -0)
===================================================================
--- test/xml-responses.js    2012-11-05 15:29:34 +0900 (3a03eee)
+++ test/xml-responses.js    2012-11-05 15:43:37 +0900 (9ce81dc)
@@ -181,6 +181,20 @@ var COMMON_ERROR_RESPONSE =
       }
     };
 
+var TYPED_ERROR_RESPONSE =
+    exports.TYPED_ERROR_RESPONSE = {
+      Response: {
+        Errors: {
+          Error: {
+            Type: '',
+            Code: '',
+            Message: ''
+          }
+        },
+        RequestID: ''
+      }
+    };
+
 var DefaultSearchFieldStatus =
     exports.DefaultSearchFieldStatus = {
       Options: '',
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る