@@ -108,174 +108,142 @@ describe("PluginKeychainGoogleSm", () => {
108
108
} ) ;
109
109
110
110
it ( ` ${ fSet } - ${ cWithoutParams } ` , async ( ) => {
111
- try {
112
- await apiClient . setKeychainEntryV1 ( {
113
- value,
114
- } as unknown as SetKeychainEntryRequestV1 ) ;
115
- } catch ( e ) {
116
- const fields = e . response . data . map ( ( param : unknown ) => {
117
- if ( ! hasKey ( param , "path" ) ) {
118
- throw new TypeError ( "Expected param.path to exist." ) ;
119
- }
120
- if ( typeof param . path !== "string" ) {
121
- throw new TypeError ( "Expected param.path to be string" ) ;
122
- }
123
- return param . path . replace ( "/body/" , "" ) ;
124
- } ) ;
125
-
126
- expect ( fields . includes ( "key" ) ) . toBeTrue ( ) ;
127
- }
111
+ const setKeychainEntryCall = apiClient . setKeychainEntryV1 ( {
112
+ value,
113
+ } as unknown as SetKeychainEntryRequestV1 ) ;
114
+
115
+ await expect ( setKeychainEntryCall ) . rejects . toMatchObject ( {
116
+ response : {
117
+ data : expect . arrayContaining ( [
118
+ expect . objectContaining ( {
119
+ path : expect . stringContaining ( "/body/" ) ,
120
+ } ) ,
121
+ ] ) ,
122
+ } ,
123
+ } ) ;
128
124
} ) ;
129
125
130
126
it ( ` ${ fGet } - ${ cWithoutParams } ` , async ( ) => {
131
- try {
132
- await apiClient . getKeychainEntryV1 (
133
- { } as unknown as GetKeychainEntryRequestV1 ,
134
- ) ;
135
- } catch ( e ) {
136
- expect ( e . response . status ) . toEqual ( 400 ) ;
137
- const fields = e . response . data . map ( ( param : unknown ) => {
138
- if ( ! hasKey ( param , "path" ) ) {
139
- throw new TypeError ( "Expected param.path to exist." ) ;
140
- }
141
- if ( typeof param . path !== "string" ) {
142
- throw new TypeError ( "Expected param.path to be string" ) ;
143
- }
144
- return param . path . replace ( "/body/" , "" ) ;
145
- } ) ;
146
-
147
- expect ( fields . includes ( "key" ) ) . toBeTrue ( ) ;
148
- }
127
+ const getKeychainEntryCall = apiClient . getKeychainEntryV1 (
128
+ { } as unknown as GetKeychainEntryRequestV1
129
+ ) ;
130
+
131
+ await expect ( getKeychainEntryCall ) . rejects . toMatchObject ( {
132
+ response : {
133
+ status : 400 ,
134
+ data : expect . arrayContaining ( [
135
+ expect . objectContaining ( {
136
+ path : expect . stringContaining ( "/body/" ) ,
137
+ } ) ,
138
+ ] ) ,
139
+ } ,
140
+ } ) ;
149
141
} ) ;
150
142
151
143
it ( ` ${ fHas } - ${ cWithoutParams } ` , async ( ) => {
152
- try {
153
- await apiClient . hasKeychainEntryV1 (
154
- { } as unknown as HasKeychainEntryRequestV1 ,
155
- ) ;
156
- } catch ( e ) {
157
- expect ( e . response . status ) . toEqual ( 400 ) ;
158
- const fields = e . response . data . map ( ( param : unknown ) => {
159
- if ( ! hasKey ( param , "path" ) ) {
160
- throw new TypeError ( "Expected param.path to exist." ) ;
161
- }
162
- if ( typeof param . path !== "string" ) {
163
- throw new TypeError ( "Expected param.path to be string" ) ;
164
- }
165
- return param . path . replace ( "/body/" , "" ) ;
166
- } ) ;
167
-
168
- expect ( fields . includes ( "key" ) ) . toBeTrue ( ) ;
169
- }
144
+ const hasKeychainEntryCall = apiClient . hasKeychainEntryV1 (
145
+ { } as unknown as HasKeychainEntryRequestV1
146
+ ) ;
147
+
148
+ await expect ( hasKeychainEntryCall ) . rejects . toMatchObject ( {
149
+ response : {
150
+ status : 400 ,
151
+ data : expect . arrayContaining ( [
152
+ expect . objectContaining ( {
153
+ path : expect . stringContaining ( "/body/" ) ,
154
+ } ) ,
155
+ ] ) ,
156
+ } ,
157
+ } ) ;
170
158
} ) ;
171
159
172
160
it ( ` ${ fDelete } - ${ cWithoutParams } ` , async ( ) => {
173
- try {
174
- await apiClient . deleteKeychainEntryV1 (
175
- { } as unknown as DeleteKeychainEntryRequestV1 ,
176
- ) ;
177
- } catch ( e ) {
178
- expect ( e . response . status ) . toEqual ( 400 ) ;
179
- const fields = e . response . data . map ( ( param : unknown ) => {
180
- if ( ! hasKey ( param , "path" ) ) {
181
- throw new TypeError ( "Expected param.path to exist." ) ;
182
- }
183
- if ( typeof param . path !== "string" ) {
184
- throw new TypeError ( "Expected param.path to be string" ) ;
185
- }
186
- return param . path . replace ( "/body/" , "" ) ;
187
- } ) ;
188
-
189
- expect ( fields . includes ( "key" ) ) . toBeTrue ( ) ;
190
- }
161
+ const deleteKeychainEntryCall = apiClient . deleteKeychainEntryV1 (
162
+ { } as unknown as DeleteKeychainEntryRequestV1
163
+ ) ;
164
+
165
+ await expect ( deleteKeychainEntryCall ) . rejects . toMatchObject ( {
166
+ response : {
167
+ status : 400 ,
168
+ data : expect . arrayContaining ( [
169
+ expect . objectContaining ( {
170
+ path : expect . stringContaining ( "/body/" ) ,
171
+ } ) ,
172
+ ] ) ,
173
+ } ,
174
+ } ) ;
191
175
} ) ;
192
176
193
177
it ( ` ${ fSet } - ${ cInvalidParams } ` , async ( ) => {
194
- try {
195
- await apiClient . setKeychainEntryV1 ( {
196
- key,
197
- value,
198
- fake : 4 ,
199
- } as any as SetKeychainEntryRequestV1 ) ;
200
- } catch ( e ) {
201
- expect ( e . response . status ) . toEqual ( 400 ) ;
202
- const fields = e . response . data . map ( ( param : unknown ) => {
203
- if ( ! hasKey ( param , "path" ) ) {
204
- throw new TypeError ( "Expected param.path to exist." ) ;
205
- }
206
- if ( typeof param . path !== "string" ) {
207
- throw new TypeError ( "Expected param.path to be string" ) ;
208
- }
209
- return param . path . replace ( "/body/" , "" ) ;
210
- } ) ;
211
-
212
- expect ( fields . includes ( "fake" ) ) . toBeTrue ( ) ;
213
- }
178
+ const setKeychainEntryCall = apiClient . setKeychainEntryV1 ( {
179
+ key,
180
+ value,
181
+ fake : 4 ,
182
+ } as any as SetKeychainEntryRequestV1 ) ;
183
+
184
+ await expect ( setKeychainEntryCall ) . rejects . toMatchObject ( {
185
+ response : {
186
+ status : 400 ,
187
+ data : expect . arrayContaining ( [
188
+ expect . objectContaining ( {
189
+ path : expect . stringContaining ( "/body/" ) ,
190
+ } ) ,
191
+ ] ) ,
192
+ } ,
193
+ } ) ;
214
194
} ) ;
215
195
216
196
it ( ` ${ fGet } - ${ cInvalidParams } ` , async ( ) => {
217
- try {
218
- await apiClient . getKeychainEntryV1 ( {
219
- key,
220
- fake : 4 ,
221
- } as unknown as GetKeychainEntryRequestV1 ) ;
222
- } catch ( e ) {
223
- expect ( e . response . status ) . toEqual ( 400 ) ;
224
- const fields = e . response . data . map ( ( param : unknown ) => {
225
- if ( ! hasKey ( param , "path" ) ) {
226
- throw new TypeError ( "Expected param.path to exist." ) ;
227
- }
228
- if ( typeof param . path !== "string" ) {
229
- throw new TypeError ( "Expected param.path to be string" ) ;
230
- }
231
- return param . path . replace ( "/body/" , "" ) ;
232
- } ) ;
233
-
234
- expect ( fields . includes ( "fake" ) ) . toBeTrue ( ) ;
235
- }
197
+ const getKeychainEntryCall = apiClient . getKeychainEntryV1 ( {
198
+ key,
199
+ fake : 4 ,
200
+ } as unknown as GetKeychainEntryRequestV1 ) ;
201
+
202
+ await expect ( getKeychainEntryCall ) . rejects . toMatchObject ( {
203
+ response : {
204
+ status : 400 ,
205
+ data : expect . arrayContaining ( [
206
+ expect . objectContaining ( {
207
+ path : expect . stringContaining ( "/body/" ) ,
208
+ } ) ,
209
+ ] ) ,
210
+ } ,
211
+ } ) ;
236
212
} ) ;
237
213
238
214
it ( ` ${ fHas } - ${ cInvalidParams } ` , async ( ) => {
239
- try {
240
- await apiClient . hasKeychainEntryV1 ( {
241
- key,
242
- fake : 4 ,
243
- } as unknown as HasKeychainEntryRequestV1 ) ;
244
- } catch ( e ) {
245
- expect ( e . response . status ) . toEqual ( 400 ) ;
246
- const fields = e . response . data . map ( ( param : unknown ) => {
247
- if ( ! hasKey ( param , "path" ) ) {
248
- throw new TypeError ( "Expected param.path to exist." ) ;
249
- }
250
- if ( typeof param . path !== "string" ) {
251
- throw new TypeError ( "Expected param.path to be string" ) ;
252
- }
253
- return param . path . replace ( "/body/" , "" ) ;
254
- } ) ;
255
-
256
- expect ( fields . includes ( "fake" ) ) . toBeTrue ( ) ;
257
- }
215
+ const hasKeychainEntryCall = apiClient . hasKeychainEntryV1 ( {
216
+ key,
217
+ fake : 4 ,
218
+ } as unknown as HasKeychainEntryRequestV1 ) ;
219
+
220
+ await expect ( hasKeychainEntryCall ) . rejects . toMatchObject ( {
221
+ response : {
222
+ status : 400 ,
223
+ data : expect . arrayContaining ( [
224
+ expect . objectContaining ( {
225
+ path : expect . stringContaining ( "/body/" ) ,
226
+ } ) ,
227
+ ] ) ,
228
+ } ,
229
+ } ) ;
258
230
} ) ;
259
231
260
232
it ( ` ${ fDelete } - ${ cInvalidParams } ` , async ( ) => {
261
- try {
262
- await apiClient . deleteKeychainEntryV1 ( {
263
- key,
264
- fake : 4 ,
265
- } as unknown as DeleteKeychainEntryRequestV1 ) ;
266
- } catch ( e ) {
267
- expect ( e . response . status ) . toEqual ( 400 ) ;
268
- const fields = e . response . data . map ( ( param : unknown ) => {
269
- if ( ! hasKey ( param , "path" ) ) {
270
- throw new TypeError ( "Expected param.path to exist." ) ;
271
- }
272
- if ( typeof param . path !== "string" ) {
273
- throw new TypeError ( "Expected param.path to be string" ) ;
274
- }
275
- return param . path . replace ( "/body/" , "" ) ;
276
- } ) ;
277
-
278
- expect ( fields . includes ( "fake" ) ) . toBeTrue ( ) ;
279
- }
233
+ const deleteKeychainEntryCall = apiClient . deleteKeychainEntryV1 ( {
234
+ key,
235
+ fake : 4 ,
236
+ } as unknown as DeleteKeychainEntryRequestV1 ) ;
237
+
238
+ await expect ( deleteKeychainEntryCall ) . rejects . toMatchObject ( {
239
+ response : {
240
+ status : 400 ,
241
+ data : expect . arrayContaining ( [
242
+ expect . objectContaining ( {
243
+ path : expect . stringContaining ( "/body/" ) ,
244
+ } ) ,
245
+ ] ) ,
246
+ } ,
247
+ } ) ;
280
248
} ) ;
281
249
} ) ;
0 commit comments