|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { generateAxiosOptions } from './options'; |
| 3 | + |
| 4 | +describe('generateAxiosOptions', () => { |
| 5 | + it('should return "...options"', () => { |
| 6 | + const result = generateAxiosOptions({ |
| 7 | + response: { |
| 8 | + imports: [], |
| 9 | + definition: { |
| 10 | + success: 'string', |
| 11 | + errors: 'unknown', |
| 12 | + }, |
| 13 | + isBlob: false, |
| 14 | + types: { |
| 15 | + success: [ |
| 16 | + { |
| 17 | + value: 'string', |
| 18 | + isEnum: false, |
| 19 | + type: 'string', |
| 20 | + imports: [], |
| 21 | + schemas: [], |
| 22 | + isRef: false, |
| 23 | + hasReadonlyProps: false, |
| 24 | + example: undefined, |
| 25 | + examples: undefined, |
| 26 | + originalSchema: { |
| 27 | + type: 'string', |
| 28 | + format: 'uuid', |
| 29 | + }, |
| 30 | + contentType: 'application/json', |
| 31 | + key: '200', |
| 32 | + }, |
| 33 | + ], |
| 34 | + errors: [], |
| 35 | + }, |
| 36 | + contentTypes: ['application/json'], |
| 37 | + schemas: [], |
| 38 | + originalSchema: { |
| 39 | + '200': { |
| 40 | + content: { |
| 41 | + 'application/json': { |
| 42 | + schema: { |
| 43 | + type: 'string', |
| 44 | + format: 'uuid', |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + isExactOptionalPropertyTypes: false, |
| 52 | + queryParams: undefined, |
| 53 | + headers: undefined, |
| 54 | + requestOptions: true, |
| 55 | + hasSignal: false, |
| 56 | + isVue: false, |
| 57 | + isAngular: false, |
| 58 | + paramsSerializer: undefined, |
| 59 | + paramsSerializerOptions: undefined, |
| 60 | + }); |
| 61 | + expect(result).toBe('\n ...options,'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should return "options"', () => { |
| 65 | + const result = generateAxiosOptions({ |
| 66 | + response: { |
| 67 | + imports: [ |
| 68 | + { |
| 69 | + name: 'Pet', |
| 70 | + specKey: undefined, |
| 71 | + schemaName: 'Pet', |
| 72 | + }, |
| 73 | + ], |
| 74 | + definition: { |
| 75 | + success: 'Pet', |
| 76 | + errors: 'unknown', |
| 77 | + }, |
| 78 | + isBlob: false, |
| 79 | + types: { |
| 80 | + success: [ |
| 81 | + { |
| 82 | + value: 'Pet', |
| 83 | + imports: [ |
| 84 | + { |
| 85 | + name: 'Pet', |
| 86 | + specKey: undefined, |
| 87 | + schemaName: 'Pet', |
| 88 | + }, |
| 89 | + ], |
| 90 | + type: 'object', |
| 91 | + schemas: [], |
| 92 | + isEnum: false, |
| 93 | + originalSchema: { |
| 94 | + type: 'object', |
| 95 | + required: ['id', 'name'], |
| 96 | + properties: { |
| 97 | + id: { |
| 98 | + type: 'integer', |
| 99 | + format: 'int64', |
| 100 | + }, |
| 101 | + name: { |
| 102 | + type: 'string', |
| 103 | + }, |
| 104 | + tag: { |
| 105 | + type: 'string', |
| 106 | + }, |
| 107 | + status: { |
| 108 | + $ref: '#/components/schemas/Domain.Status.Enum', |
| 109 | + }, |
| 110 | + email: { |
| 111 | + type: 'string', |
| 112 | + format: 'email', |
| 113 | + }, |
| 114 | + }, |
| 115 | + }, |
| 116 | + hasReadonlyProps: false, |
| 117 | + isRef: true, |
| 118 | + contentType: 'application/json', |
| 119 | + example: undefined, |
| 120 | + examples: undefined, |
| 121 | + key: '200', |
| 122 | + }, |
| 123 | + ], |
| 124 | + errors: [], |
| 125 | + }, |
| 126 | + contentTypes: ['application/json'], |
| 127 | + schemas: [], |
| 128 | + originalSchema: { |
| 129 | + '200': { |
| 130 | + content: { |
| 131 | + 'application/json': { |
| 132 | + schema: { |
| 133 | + $ref: '#/components/schemas/Pet', |
| 134 | + }, |
| 135 | + }, |
| 136 | + }, |
| 137 | + }, |
| 138 | + }, |
| 139 | + }, |
| 140 | + isExactOptionalPropertyTypes: false, |
| 141 | + queryParams: undefined, |
| 142 | + headers: undefined, |
| 143 | + requestOptions: true, |
| 144 | + hasSignal: true, |
| 145 | + isVue: false, |
| 146 | + isAngular: false, |
| 147 | + paramsSerializer: undefined, |
| 148 | + paramsSerializerOptions: undefined, |
| 149 | + }); |
| 150 | + expect(result).toBe('options'); |
| 151 | + }); |
| 152 | + |
| 153 | + it(`should return "responseType: 'text', ...options"`, () => { |
| 154 | + const result = generateAxiosOptions({ |
| 155 | + response: { |
| 156 | + imports: [], |
| 157 | + definition: { |
| 158 | + success: 'string', |
| 159 | + errors: 'unknown', |
| 160 | + }, |
| 161 | + isBlob: false, |
| 162 | + types: { |
| 163 | + success: [ |
| 164 | + { |
| 165 | + value: 'string', |
| 166 | + isEnum: false, |
| 167 | + type: 'string', |
| 168 | + imports: [], |
| 169 | + schemas: [], |
| 170 | + isRef: false, |
| 171 | + hasReadonlyProps: false, |
| 172 | + example: undefined, |
| 173 | + examples: undefined, |
| 174 | + originalSchema: { |
| 175 | + type: 'string', |
| 176 | + format: 'uuid', |
| 177 | + }, |
| 178 | + contentType: 'text/plain', |
| 179 | + key: '200', |
| 180 | + }, |
| 181 | + ], |
| 182 | + errors: [], |
| 183 | + }, |
| 184 | + contentTypes: ['text/plain'], |
| 185 | + schemas: [], |
| 186 | + originalSchema: { |
| 187 | + '200': { |
| 188 | + content: { |
| 189 | + 'text/plain': { |
| 190 | + schema: { |
| 191 | + type: 'string', |
| 192 | + format: 'uuid', |
| 193 | + }, |
| 194 | + }, |
| 195 | + }, |
| 196 | + }, |
| 197 | + }, |
| 198 | + }, |
| 199 | + isExactOptionalPropertyTypes: false, |
| 200 | + queryParams: undefined, |
| 201 | + headers: undefined, |
| 202 | + requestOptions: true, |
| 203 | + hasSignal: true, |
| 204 | + isVue: true, |
| 205 | + isAngular: false, |
| 206 | + paramsSerializer: undefined, |
| 207 | + paramsSerializerOptions: undefined, |
| 208 | + }); |
| 209 | + expect(result).toBe("\n responseType: 'text',\n ...options,"); |
| 210 | + }); |
| 211 | +}); |
0 commit comments