Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | /* jshint -W100 */ |
| 20 | |
| 21 | /* |
| 22 | * Fully Async JavaScript test suite for ThriftTest.thrift. |
| 23 | * These tests are designed to exercise the WebSocket transport |
| 24 | * (which is exclusively async). |
| 25 | * |
| 26 | * To compile client code for this test use: |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 27 | * $ thrift -gen js:es6 ThriftTest.thrift |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 28 | */ |
| 29 | |
| 30 | |
| 31 | |
| 32 | // all Languages in UTF-8 |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 33 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 34 | const stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, Bahasa Melayu, مازِرونی, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, Occitan, Иронау, Papiamentu, Deitsch, Norfuk / Pitkern, Polski, پنجابی, پښتو, Português, Runa Simi, Rumantsch, Romani, Română, Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, Bân-lâm-gú, 粵語"; |
| 35 | |
| 36 | function checkRecursively(assert, map1, map2) { |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 37 | if (typeof map1 !== 'function' && typeof map2 !== 'function') { |
| 38 | if (!map1 || typeof map1 !== 'object') { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 39 | assert.equal(map1, map2); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 40 | } else { |
| 41 | for (var key in map1) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 42 | checkRecursively(assert, map1[key], map2[key]); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 48 | QUnit.module('Base Types'); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 49 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 50 | QUnit.test('Void', function( assert ) { |
| 51 | assert.expect(1); |
| 52 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 53 | client.testVoid().then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 54 | assert.equal(result, undefined); |
| 55 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 56 | }); |
| 57 | }); |
| 58 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 59 | QUnit.test('String', function( assert ) { |
| 60 | assert.expect(3); |
| 61 | const done = assert.async(3); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 62 | client.testString('').then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 63 | assert.equal(result, ''); |
| 64 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 65 | }); |
| 66 | client.testString(stringTest).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 67 | assert.equal(result, stringTest); |
| 68 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 69 | }); |
| 70 | var specialCharacters = 'quote: \" backslash:' + |
| 71 | ' forwardslash-escaped: \/ ' + |
| 72 | ' backspace: \b formfeed: \f newline: \n return: \r tab: ' + |
| 73 | ' now-all-of-them-together: "\\\/\b\n\r\t' + |
| 74 | ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><'; |
| 75 | client.testString(specialCharacters).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 76 | assert.equal(result, specialCharacters); |
| 77 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 78 | }); |
| 79 | }); |
| 80 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 81 | QUnit.test('Double', function( assert ) { |
| 82 | assert.expect(4); |
| 83 | const done = assert.async(4); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 84 | client.testDouble(0).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 85 | assert.equal(result, 0); |
| 86 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 87 | }); |
| 88 | client.testDouble(-1).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 89 | assert.equal(result, -1); |
| 90 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 91 | }); |
| 92 | client.testDouble(3.14).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 93 | assert.equal(result, 3.14); |
| 94 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 95 | }); |
| 96 | client.testDouble(Math.pow(2, 60)).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 97 | assert.equal(result, Math.pow(2, 60)); |
| 98 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 99 | }); |
| 100 | }); |
| 101 | // TODO: add testBinary() |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 102 | QUnit.test('Byte', function( assert ) { |
| 103 | assert.expect(2); |
| 104 | const done = assert.async(2); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 105 | client.testByte(0).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 106 | assert.equal(result, 0); |
| 107 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 108 | }); |
| 109 | client.testByte(0x01).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 110 | assert.equal(result, 0x01); |
| 111 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 112 | }); |
| 113 | }); |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 114 | QUnit.test('I32', function( assert ) { |
| 115 | assert.expect(3); |
| 116 | const done = assert.async(3); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 117 | client.testI32(0).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 118 | assert.equal(result, 0); |
| 119 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 120 | }); |
| 121 | client.testI32(Math.pow(2, 30)).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 122 | assert.equal(result, Math.pow(2, 30)); |
| 123 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 124 | }); |
| 125 | client.testI32(-Math.pow(2, 30)).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 126 | assert.equal(result, -Math.pow(2, 30)); |
| 127 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 128 | }); |
| 129 | }); |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 130 | QUnit.test('I64', function( assert ) { |
| 131 | assert.expect(3); |
| 132 | const done = assert.async(3); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 133 | client.testI64(0).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 134 | assert.equal(result, 0); |
| 135 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 136 | }); |
| 137 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 138 | client.testI64(Math.pow(2, 52)).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 139 | assert.equal(result, Math.pow(2, 52)); |
| 140 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 141 | }); |
| 142 | client.testI64(-Math.pow(2, 52)).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 143 | assert.equal(result, -Math.pow(2, 52)); |
| 144 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 145 | }); |
| 146 | }); |
| 147 | |
| 148 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 149 | QUnit.module('Structured Types'); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 150 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 151 | QUnit.test('Struct', function( assert ) { |
| 152 | assert.expect(5); |
| 153 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 154 | var structTestInput = new ThriftTest.Xtruct(); |
| 155 | structTestInput.string_thing = 'worked'; |
| 156 | structTestInput.byte_thing = 0x01; |
| 157 | structTestInput.i32_thing = Math.pow(2, 30); |
| 158 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 159 | structTestInput.i64_thing = Math.pow(2, 52); |
| 160 | |
| 161 | client.testStruct(structTestInput).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 162 | assert.equal(result.string_thing, structTestInput.string_thing); |
| 163 | assert.equal(result.byte_thing, structTestInput.byte_thing); |
| 164 | assert.equal(result.i32_thing, structTestInput.i32_thing); |
| 165 | assert.equal(result.i64_thing, structTestInput.i64_thing); |
| 166 | assert.equal(JSON.stringify(result), JSON.stringify(structTestInput)); |
| 167 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 168 | }); |
| 169 | }); |
| 170 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 171 | QUnit.test('Nest', function( assert ) { |
| 172 | assert.expect(7); |
| 173 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 174 | var xtrTestInput = new ThriftTest.Xtruct(); |
| 175 | xtrTestInput.string_thing = 'worked'; |
| 176 | xtrTestInput.byte_thing = 0x01; |
| 177 | xtrTestInput.i32_thing = Math.pow(2, 30); |
| 178 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 179 | xtrTestInput.i64_thing = Math.pow(2, 52); |
| 180 | |
| 181 | var nestTestInput = new ThriftTest.Xtruct2(); |
| 182 | nestTestInput.byte_thing = 0x02; |
| 183 | nestTestInput.struct_thing = xtrTestInput; |
| 184 | nestTestInput.i32_thing = Math.pow(2, 15); |
| 185 | |
| 186 | client.testNest(nestTestInput).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 187 | assert.equal(result.byte_thing, nestTestInput.byte_thing); |
| 188 | assert.equal(result.struct_thing.string_thing, nestTestInput.struct_thing.string_thing); |
| 189 | assert.equal(result.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing); |
| 190 | assert.equal(result.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing); |
| 191 | assert.equal(result.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing); |
| 192 | assert.equal(result.i32_thing, nestTestInput.i32_thing); |
| 193 | assert.equal(JSON.stringify(result), JSON.stringify(nestTestInput)); |
| 194 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 195 | }); |
| 196 | }); |
| 197 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 198 | QUnit.test('Map', function( assert ) { |
| 199 | assert.expect(3); |
| 200 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 201 | var mapTestInput = {7: 77, 8: 88, 9: 99}; |
| 202 | |
| 203 | client.testMap(mapTestInput).then(function(result) { |
| 204 | for (var key in result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 205 | assert.equal(result[key], mapTestInput[key]); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 206 | } |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 207 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 208 | }); |
| 209 | }); |
| 210 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 211 | QUnit.test('StringMap', function( assert ) { |
| 212 | assert.expect(6); |
| 213 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 214 | var mapTestInput = { |
| 215 | 'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key', |
| 216 | 'longValue': stringTest, stringTest: 'long key' |
| 217 | }; |
| 218 | |
| 219 | client.testStringMap(mapTestInput).then(function(result) { |
| 220 | for (var key in result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 221 | assert.equal(result[key], mapTestInput[key]); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 222 | } |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 223 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 224 | }); |
| 225 | }); |
| 226 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 227 | QUnit.test('Set', function( assert ) { |
| 228 | assert.expect(1); |
| 229 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 230 | var setTestInput = [1, 2, 3]; |
| 231 | client.testSet(setTestInput).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 232 | assert.ok(result, setTestInput); |
| 233 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 234 | }); |
| 235 | }); |
| 236 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 237 | QUnit.test('List', function( assert ) { |
| 238 | assert.expect(1); |
| 239 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 240 | var listTestInput = [1, 2, 3]; |
| 241 | client.testList(listTestInput).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 242 | assert.ok(result, listTestInput); |
| 243 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 244 | }); |
| 245 | }); |
| 246 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 247 | QUnit.test('Enum', function( assert ) { |
| 248 | assert.expect(1); |
| 249 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 250 | client.testEnum(ThriftTest.Numberz.ONE).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 251 | assert.equal(result, ThriftTest.Numberz.ONE); |
| 252 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 253 | }); |
| 254 | }); |
| 255 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 256 | QUnit.test('TypeDef', function( assert ) { |
| 257 | assert.expect(1); |
| 258 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 259 | client.testTypedef(69).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 260 | assert.equal(result, 69); |
| 261 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 262 | }); |
| 263 | }); |
| 264 | |
| 265 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 266 | QUnit.module('deeper!'); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 267 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 268 | QUnit.test('MapMap', function( assert ) { |
| 269 | assert.expect(16); |
| 270 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 271 | var mapMapTestExpectedResult = { |
| 272 | '4': {'1': 1, '2': 2, '3': 3, '4': 4}, |
| 273 | '-4': {'-4': -4, '-3': -3, '-2': -2, '-1': -1} |
| 274 | }; |
| 275 | |
| 276 | client.testMapMap(1).then(function(result) { |
| 277 | for (var key in result) { |
| 278 | for (var key2 in result[key]) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 279 | assert.equal(result[key][key2], mapMapTestExpectedResult[key][key2]); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 280 | } |
| 281 | } |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 282 | checkRecursively(assert, result, mapMapTestExpectedResult); |
| 283 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 284 | }); |
| 285 | }); |
| 286 | |
| 287 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 288 | QUnit.module('Exception'); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 289 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 290 | QUnit.test('Xception', function( assert ) { |
| 291 | assert.expect(2); |
| 292 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 293 | client.testException('Xception').then(function(res) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 294 | assert.ok(false); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 295 | }).catch(function(e) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 296 | |
| 297 | console.log(`Exception exception e`); |
| 298 | console.log(e); |
| 299 | console.log(JSON.stringify(e, null, 2)); |
| 300 | |
| 301 | assert.equal(e.errorCode, 1001); |
| 302 | assert.equal(e.message, 'Xception'); |
| 303 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 304 | }); |
| 305 | }); |
| 306 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 307 | QUnit.test('no Exception', function( assert ) { |
| 308 | assert.expect(1); |
| 309 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 310 | client.testException('no Exception').then(function(e) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 311 | assert.ok(!e); |
| 312 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 313 | }); |
| 314 | }); |
| 315 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 316 | QUnit.module('Insanity'); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 317 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 318 | QUnit.test('testInsanity', function( assert ) { |
| 319 | assert.expect(24); |
| 320 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 321 | var insanity = { |
| 322 | '1': { |
| 323 | '2': { |
| 324 | 'userMap': { '5': 5, '8': 8 }, |
| 325 | 'xtructs': [{ |
| 326 | 'string_thing': 'Goodbye4', |
| 327 | 'byte_thing': 4, |
| 328 | 'i32_thing': 4, |
| 329 | 'i64_thing': 4 |
| 330 | }, |
| 331 | { |
| 332 | 'string_thing': 'Hello2', |
| 333 | 'byte_thing': 2, |
| 334 | 'i32_thing': 2, |
| 335 | 'i64_thing': 2 |
| 336 | } |
| 337 | ] |
| 338 | }, |
| 339 | '3': { |
| 340 | 'userMap': { '5': 5, '8': 8 }, |
| 341 | 'xtructs': [{ |
| 342 | 'string_thing': 'Goodbye4', |
| 343 | 'byte_thing': 4, |
| 344 | 'i32_thing': 4, |
| 345 | 'i64_thing': 4 |
| 346 | }, |
| 347 | { |
| 348 | 'string_thing': 'Hello2', |
| 349 | 'byte_thing': 2, |
| 350 | 'i32_thing': 2, |
| 351 | 'i64_thing': 2 |
| 352 | } |
| 353 | ] |
| 354 | } |
| 355 | }, |
| 356 | '2': { '6': { 'userMap': null, 'xtructs': null } } |
| 357 | }; |
| 358 | client.testInsanity(new ThriftTest.Insanity()).then(function(res) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 359 | assert.ok(res, JSON.stringify(res)); |
| 360 | assert.ok(insanity, JSON.stringify(insanity)); |
| 361 | checkRecursively(assert, res, insanity); |
| 362 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 363 | }); |
| 364 | }); |
| 365 | |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 366 | QUnit.module('Oneway'); |
| 367 | QUnit.test('testOneway', function( assert ) { |
| 368 | assert.expect(1); |
| 369 | const done = assert.async(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 370 | client.testOneway(1).then(function(result) { |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 371 | assert.equal(result, undefined); |
| 372 | done(); |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 373 | }); |
Brian Forbis | b5d6ea3 | 2018-08-25 23:39:29 -0400 | [diff] [blame^] | 374 | }); |