github.com/grpc-ecosystem/grpc-gateway/v2@v2.19.1/examples/internal/browser/a_bit_of_everything_service.spec.js (about)

     1  'use strict';
     2  
     3  var SwaggerClient = require('swagger-client');
     4  
     5  describe('ABitOfEverythingService', function () {
     6    var client;
     7  
     8    beforeEach(function (done) {
     9      new SwaggerClient({
    10        url: "http://localhost:8080/openapiv2/a_bit_of_everything.swagger.json",
    11        usePromise: true,
    12      }).then(function (c) {
    13        client = c;
    14      }).catch(function (err) {
    15        done.fail(err);
    16      }).then(done);
    17    });
    18  
    19    describe('Create', function () {
    20      var created;
    21      var expected = {
    22        floatValue: 1.5,
    23        doubleValue: 2.5,
    24        int64Value: "4294967296",
    25        uint64Value: "9223372036854775807",
    26        int32Value: -2147483648,
    27        fixed64Value: "9223372036854775807",
    28        fixed32Value: 4294967295,
    29        boolValue: true,
    30        stringValue: "strprefix/foo",
    31        uint32Value: 4294967295,
    32        sfixed32Value: 2147483647,
    33        sfixed64Value: "-4611686018427387904",
    34        sint32Value: 2147483647,
    35        sint64Value: "4611686018427387903",
    36        nonConventionalNameValue: "camelCase",
    37        enumValue: "ONE",
    38        pathEnumValue: "DEF",
    39        nestedPathEnumValue: "JKL",
    40        enumValueAnnotation: "ONE",
    41        requiredStringViaFieldBehaviorAnnotation: "foo",
    42        singleNested: null,
    43        nested: [],
    44        bytesValue: "",
    45        repeatedStringValue: [],
    46        mapValue: {},
    47        mappedStringValue: {},
    48        mappedNestedValue: {},
    49        timestampValue: "2006-01-02T15:04:05Z",
    50        repeatedEnumValue: [],
    51        repeatedEnumAnnotation: [],
    52        repeatedStringAnnotation: [],
    53        repeatedNestedAnnotation: [],
    54        nestedAnnotation: null,
    55        int64OverrideType: "0",
    56        outputOnlyStringViaFieldBehaviorAnnotation: "",
    57      };
    58  
    59      beforeEach(function (done) {
    60        client.ABitOfEverythingService.ABitOfEverythingService_Create(expected).then(function (resp) {
    61          created = resp.obj;
    62        }).catch(function (err) {
    63          done.fail(err);
    64        }).then(done);
    65      });
    66  
    67      it('should assign id', function () {
    68        expect(created.uuid).not.toBe("");
    69      });
    70  
    71      it('should echo the request back', function () {
    72        delete created.uuid;
    73        expect(created).toEqual(expected);
    74      });
    75    });
    76  
    77    describe('CreateBody', function () {
    78      var created;
    79      var expected = {
    80        floatValue: 1.5,
    81        doubleValue: 2.5,
    82        int64Value: "4294967296",
    83        uint64Value: "9223372036854775807",
    84        int32Value: -2147483648,
    85        fixed64Value: "9223372036854775807",
    86        fixed32Value: 4294967295,
    87        boolValue: true,
    88        stringValue: "strprefix/foo",
    89        uint32Value: 4294967295,
    90        sfixed32Value: 2147483647,
    91        sfixed64Value: "-4611686018427387904",
    92        sint32Value: 2147483647,
    93        sint64Value: "4611686018427387903",
    94        nonConventionalNameValue: "camelCase",
    95        enumValue: "ONE",
    96        pathEnumValue: "DEF",
    97        nestedPathEnumValue: "JKL",
    98        nested: [
    99          { name: "bar", amount: 10 },
   100          { name: "baz", amount: 20 },
   101        ],
   102        repeatedStringValue: ["a", "b", "c"],
   103        oneofString: "x",
   104        mapValue: { a: "ONE", b: 2 },
   105        mappedStringValue: { a: "x", b: "y" },
   106        mappedNestedValue: {
   107          a: { name: "x", amount: 1 },
   108          b: { name: "y", amount: 2 },
   109        },
   110        enumValueAnnotation: "ONE",
   111        requiredStringViaFieldBehaviorAnnotation: "foo",
   112        singleNested: null,
   113        nested: [],
   114        bytesValue: "",
   115        repeatedStringValue: [],
   116        mapValue: {},
   117        mappedStringValue: {},
   118        mappedNestedValue: {},
   119        timestampValue: "2006-01-02T15:04:05Z",
   120        repeatedEnumValue: [],
   121        repeatedEnumAnnotation: [],
   122        repeatedStringAnnotation: [],
   123        repeatedNestedAnnotation: [],
   124        nestedAnnotation: null,
   125        int64OverrideType: "0",
   126        outputOnlyStringViaFieldBehaviorAnnotation: "",
   127      };
   128  
   129      beforeEach(function (done) {
   130        client.ABitOfEverythingService.ABitOfEverythingService_CreateBody({
   131          body: expected,
   132        }).then(function (resp) {
   133          created = resp.obj;
   134        }).catch(function (err) {
   135          done.fail(err);
   136        }).then(done);
   137      });
   138  
   139      it('should assign id', function () {
   140        expect(created.uuid).not.toBe("");
   141      });
   142  
   143      it('should echo the request back', function () {
   144        delete created.uuid;
   145        expect(created).toEqual(expected);
   146      });
   147    });
   148  
   149    describe('lookup', function () {
   150      var created;
   151      var expected = {
   152        boolValue: true,
   153        stringValue: "strprefix/foo",
   154      };
   155  
   156      beforeEach(function (done) {
   157        client.ABitOfEverythingService.ABitOfEverythingService_CreateBody({
   158          body: expected,
   159        }).then(function (resp) {
   160          created = resp.obj;
   161        }).catch(function (err) {
   162          fail(err);
   163        }).finally(done);
   164      });
   165  
   166      it('should look up an object by uuid', function (done) {
   167        client.ABitOfEverythingService.ABitOfEverythingService_Lookup({
   168          uuid: created.uuid
   169        }).then(function (resp) {
   170          expect(resp.obj).toEqual(created);
   171        }).catch(function (err) {
   172          fail(err.errObj);
   173        }).finally(done);
   174      });
   175  
   176      it('should fail if no such object', function (done) {
   177        client.ABitOfEverythingService.ABitOfEverythingService_Lookup({
   178          uuid: 'not_exist',
   179        }).then(function (resp) {
   180          fail('expected failure but succeeded');
   181        }).catch(function (err) {
   182          expect(err.status).toBe(404);
   183        }).finally(done);
   184      });
   185    });
   186  
   187    describe('Delete', function () {
   188      var created;
   189      var expected = {
   190        boolValue: true,
   191        stringValue: "strprefix/foo",
   192      };
   193  
   194      beforeEach(function (done) {
   195        client.ABitOfEverythingService.ABitOfEverythingService_CreateBody({
   196          body: expected,
   197        }).then(function (resp) {
   198          created = resp.obj;
   199        }).catch(function (err) {
   200          fail(err);
   201        }).finally(done);
   202      });
   203  
   204      it('should delete an object by id', function (done) {
   205        client.ABitOfEverythingService.ABitOfEverythingService_Delete({
   206          uuid: created.uuid
   207        }).then(function (resp) {
   208          expect(resp.obj).toEqual({});
   209        }).catch(function (err) {
   210          fail(err.errObj);
   211        }).then(function () {
   212          return client.ABitOfEverythingService.ABitOfEverythingService_Lookup({
   213            uuid: created.uuid
   214          });
   215        }).then(function (resp) {
   216          fail('expected failure but succeeded');
   217        }).catch(function (err) {
   218          expect(err.status).toBe(404);
   219        }).finally(done);
   220      });
   221    });
   222  
   223    describe('GetRepeatedQuery', function () {
   224      var repeated;
   225      var expected = {
   226        pathRepeatedFloatValue: [1.5, -1.5],
   227        pathRepeatedDoubleValue: [2.5, -2.5],
   228        pathRepeatedInt64Value: ["4294967296", "-4294967296"],
   229        pathRepeatedUint64Value: ["0", "9223372036854775807"],
   230        pathRepeatedInt32Value: [2147483647, -2147483648],
   231        pathRepeatedFixed64Value: ["0", "9223372036854775807"],
   232        pathRepeatedFixed32Value: [0, 4294967295],
   233        pathRepeatedBoolValue: [true, false],
   234        pathRepeatedStringValue: ["foo", "bar"],
   235        pathRepeatedBytesValue: ["AA==", "_w=="],
   236        pathRepeatedUint32Value: [4294967295, 0],
   237        pathRepeatedEnumValue: ["ONE", "ONE"],
   238        pathRepeatedSfixed32Value: [-2147483648, 2147483647],
   239        pathRepeatedSfixed64Value: ["-4294967296", "4294967296"],
   240        pathRepeatedSint32Value: [2147483646, -2147483647],
   241        pathRepeatedSint64Value: ["4611686018427387903", "-4611686018427387904"]
   242      };
   243  
   244      beforeEach(function (done) {
   245        client.ABitOfEverythingService.ABitOfEverythingService_GetRepeatedQuery(expected).then(function (resp) {
   246          repeated = resp.obj;
   247        }).catch(function (err) {
   248          done.fail(err);
   249        }).then(done);
   250      });
   251  
   252      it('should echo the request back', function () {
   253        // API will echo a non URL safe encoding
   254        expected.pathRepeatedBytesValue = ["AA==", "/w=="];
   255        expect(repeated).toEqual(expected);
   256      });
   257    });
   258  });