|
| 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/swagger/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 | + float_value: 1.5, |
| 23 | + double_value: 2.5, |
| 24 | + int64_value: "4294967296", |
| 25 | + uint64_value: "9223372036854775807", |
| 26 | + int32_value: -2147483648, |
| 27 | + fixed64_value: "9223372036854775807", |
| 28 | + fixed32_value: 4294967295, |
| 29 | + bool_value: true, |
| 30 | + string_value: "strprefix/foo", |
| 31 | + uint32_value: 4294967295, |
| 32 | + sfixed32_value: 2147483647, |
| 33 | + sfixed64_value: "-4611686018427387904", |
| 34 | + sint32_value: 2147483647, |
| 35 | + sint64_value: "4611686018427387903", |
| 36 | + nonConventionalNameValue: "camelCase", |
| 37 | + }; |
| 38 | + |
| 39 | + beforeEach(function(done) { |
| 40 | + client.ABitOfEverythingService.Create(expected).then(function(resp) { |
| 41 | + created = resp.obj; |
| 42 | + }).catch(function(err) { |
| 43 | + done.fail(err); |
| 44 | + }).then(done); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should assign id', function() { |
| 48 | + expect(created.uuid).not.toBe(""); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should echo the request back', function() { |
| 52 | + delete created.uuid; |
| 53 | + expect(created).toEqual(expected); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('CreateBody', function() { |
| 58 | + var created; |
| 59 | + var expected = { |
| 60 | + float_value: 1.5, |
| 61 | + double_value: 2.5, |
| 62 | + int64_value: "4294967296", |
| 63 | + uint64_value: "9223372036854775807", |
| 64 | + int32_value: -2147483648, |
| 65 | + fixed64_value: "9223372036854775807", |
| 66 | + fixed32_value: 4294967295, |
| 67 | + bool_value: true, |
| 68 | + string_value: "strprefix/foo", |
| 69 | + uint32_value: 4294967295, |
| 70 | + sfixed32_value: 2147483647, |
| 71 | + sfixed64_value: "-4611686018427387904", |
| 72 | + sint32_value: 2147483647, |
| 73 | + sint64_value: "4611686018427387903", |
| 74 | + nonConventionalNameValue: "camelCase", |
| 75 | + |
| 76 | + nested: [ |
| 77 | + { name: "bar", amount: 10 }, |
| 78 | + { name: "baz", amount: 20 }, |
| 79 | + ], |
| 80 | + repeated_string_value: ["a", "b", "c"], |
| 81 | + oneof_string: "x", |
| 82 | + // TODO(yugui) Support enum by name |
| 83 | + map_value: { a: 1, b: 2 }, |
| 84 | + mapped_string_value: { a: "x", b: "y" }, |
| 85 | + mapped_nested_value: { |
| 86 | + a: { name: "x", amount: 1 }, |
| 87 | + b: { name: "y", amount: 2 }, |
| 88 | + }, |
| 89 | + }; |
| 90 | + |
| 91 | + beforeEach(function(done) { |
| 92 | + client.ABitOfEverythingService.CreateBody({ |
| 93 | + body: expected, |
| 94 | + }).then(function(resp) { |
| 95 | + created = resp.obj; |
| 96 | + }).catch(function(err) { |
| 97 | + done.fail(err); |
| 98 | + }).then(done); |
| 99 | + }); |
| 100 | + |
| 101 | + it('should assign id', function() { |
| 102 | + expect(created.uuid).not.toBe(""); |
| 103 | + }); |
| 104 | + |
| 105 | + it('should echo the request back', function() { |
| 106 | + delete created.uuid; |
| 107 | + expect(created).toEqual(expected); |
| 108 | + }); |
| 109 | + }); |
| 110 | + |
| 111 | + describe('lookup', function() { |
| 112 | + var created; |
| 113 | + var expected = { |
| 114 | + bool_value: true, |
| 115 | + string_value: "strprefix/foo", |
| 116 | + }; |
| 117 | + |
| 118 | + beforeEach(function(done) { |
| 119 | + client.ABitOfEverythingService.CreateBody({ |
| 120 | + body: expected, |
| 121 | + }).then(function(resp) { |
| 122 | + created = resp.obj; |
| 123 | + }).catch(function(err) { |
| 124 | + fail(err); |
| 125 | + }).finally(done); |
| 126 | + }); |
| 127 | + |
| 128 | + it('should look up an object by uuid', function(done) { |
| 129 | + client.ABitOfEverythingService.Lookup({ |
| 130 | + uuid: created.uuid |
| 131 | + }).then(function(resp) { |
| 132 | + expect(resp.obj).toEqual(created); |
| 133 | + }).catch(function(err) { |
| 134 | + fail(err.errObj); |
| 135 | + }).finally(done); |
| 136 | + }); |
| 137 | + |
| 138 | + it('should fail if no such object', function(done) { |
| 139 | + client.ABitOfEverythingService.Lookup({ |
| 140 | + uuid: 'not_exist', |
| 141 | + }).then(function(resp) { |
| 142 | + fail('expected failure but succeeded'); |
| 143 | + }).catch(function(err) { |
| 144 | + expect(err.status).toBe(404); |
| 145 | + }).finally(done); |
| 146 | + }); |
| 147 | + }); |
| 148 | + |
| 149 | + describe('Delete', function() { |
| 150 | + var created; |
| 151 | + var expected = { |
| 152 | + bool_value: true, |
| 153 | + string_value: "strprefix/foo", |
| 154 | + }; |
| 155 | + |
| 156 | + beforeEach(function(done) { |
| 157 | + client.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 delete an object by id', function(done) { |
| 167 | + client.ABitOfEverythingService.Delete({ |
| 168 | + uuid: created.uuid |
| 169 | + }).then(function(resp) { |
| 170 | + expect(resp.obj).toEqual({}); |
| 171 | + }).catch(function(err) { |
| 172 | + fail(err.errObj); |
| 173 | + }).then(function() { |
| 174 | + return client.ABitOfEverythingService.Lookup({ |
| 175 | + uuid: created.uuid |
| 176 | + }); |
| 177 | + }).then(function(resp) { |
| 178 | + fail('expected failure but succeeded'); |
| 179 | + }). catch(function(err) { |
| 180 | + expect(err.status).toBe(404); |
| 181 | + }).finally(done); |
| 182 | + }); |
| 183 | + }); |
| 184 | +}); |
| 185 | + |
0 commit comments