Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Commit f6761a8

Browse files
Austin Kingdino-rodriguez
andauthored
New AdminAPI format PUT tests (#680)
* feat: new format GET admin API * feat: PUT tests for new format * lint & update import * updated tests * fix: remove GET tests * fix tests Co-authored-by: Dino Rodriguez <[email protected]>
1 parent 663ef74 commit f6761a8

File tree

1 file changed

+239
-1
lines changed

1 file changed

+239
-1
lines changed

test/integration/e2e/admin-api/putUsers.test.ts

Lines changed: 239 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
/* eslint-disable max-lines -- I think it's fine to have > 500 lines for testing */
12
import HttpStatus from '@xpring-eng/http-status'
23
import * as request from 'supertest'
34
import 'mocha'
45

56
import App from '../../../../src/app'
7+
import { adminApiVersions, payIdServerVersions } from '../../../../src/config'
8+
import { AddressDetailsType } from '../../../../src/types/protocol'
69
import { appSetup, appCleanup } from '../../../helpers/helpers'
710

811
let app: App
9-
const payIdApiVersion = '2020-05-28'
12+
const payIdApiVersion = adminApiVersions[0]
13+
const payIdNextApiVersion = adminApiVersions[1]
14+
const payIdProtocolVersion = payIdServerVersions[1]
1015

1116
const acceptPatch = 'application/merge-patch+json'
1217

@@ -122,6 +127,239 @@ describe('E2E - adminApiRouter - PUT /users', function (): void {
122127
.expect(HttpStatus.OK, updatedInformation, done)
123128
})
124129

130+
it('Returns a 200 when updating a user with the canonical format', function (done): void {
131+
// GIVEN a user with a PayID known to exist on the PayID service
132+
const updatedInformation = {
133+
payId: 'nextversion$127.0.0.1',
134+
version: payIdProtocolVersion,
135+
addresses: [
136+
{
137+
paymentNetwork: 'BTC',
138+
environment: 'TESTNET',
139+
addressDetailsType: AddressDetailsType.CryptoAddress,
140+
addressDetails: {
141+
address: 'n4VQ5YdHf7hLQ2gWQYYrcxoE5B7nWuDFNF',
142+
},
143+
},
144+
],
145+
verifiedAddresses: [
146+
{
147+
payload: JSON.stringify({
148+
payId: 'nextversion$127.0.0.1',
149+
payIdAddress: {
150+
paymentNetwork: 'XRPL',
151+
environment: 'MAINNET',
152+
addressDetailsType: AddressDetailsType.CryptoAddress,
153+
addressDetails: {
154+
address: 'rBJwwXADHqbwsp6yhrqoyt2nmFx9FB83Th',
155+
},
156+
},
157+
}),
158+
signatures: [
159+
{
160+
name: 'identityKey',
161+
protected:
162+
'eyJuYW1lIjoiaWRlbnRpdHlLZXkiLCJhbGciOiJFUzI1NksiLCJ0eXAiOiJKT1NFK0pTT04iLCJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCIsIm5hbWUiXSwiandrIjp7ImNydiI6InNlY3AyNTZrMSIsIngiOiI2S0dtcEF6WUhWUm9qVmU5UEpfWTVyZHltQ21kTy1xaVRHem1Edl9waUlvIiwieSI6ImhxS3Vnc1g3Vjk3eFRNLThCMTBONUQxcW44MUZWMjItM1p0TURXaXZfSnciLCJrdHkiOiJFQyIsImtpZCI6Im4zNlhTc0M1TjRnNUtCVzRBWXJ5d1ZtRE1kUWNEV1BJX0RfNUR1UlNhNDAifX0',
163+
signature:
164+
'bG9vayBhdCBtZSBJIGp1c3QgdXBkYXRlZCB0aGlzIFBVVCBsZXRzIGdv',
165+
},
166+
],
167+
},
168+
],
169+
}
170+
171+
// WHEN we make a PUT request to /users/ with the new information to update
172+
request(app.adminApiExpress)
173+
.put(`/users/${updatedInformation.payId}`)
174+
.set('PayID-API-Version', payIdNextApiVersion)
175+
.send(updatedInformation)
176+
.expect('Content-Type', /json/u)
177+
// THEN we expect back a 200-OK, with the updated user information
178+
// .expect(HttpStatus.OK, updatedInformation)
179+
.end(function () {
180+
request(app.adminApiExpress)
181+
.get(`/users/${updatedInformation.payId}`)
182+
.set('PayID-API-Version', payIdNextApiVersion)
183+
.expect('Content-Type', /json/u)
184+
// THEN we expect to have an Accept-Patch header in the response
185+
.expect('Accept-Patch', acceptPatch)
186+
// THEN We expect back a 200 - OK, with the account information
187+
.expect(HttpStatus.OK, updatedInformation, done)
188+
})
189+
})
190+
191+
it('Throws BadRequest error on invalid protected payload (identity key)', function (done): void {
192+
// GIVEN a user with a PayID known to exist on the PayID service
193+
const payId = 'johnwick$127.0.0.1'
194+
const userInformation = {
195+
payId,
196+
addresses: [],
197+
verifiedAddresses: [
198+
{
199+
payload: JSON.stringify({
200+
payId,
201+
payIdAddress: {
202+
paymentNetwork: 'XRPL',
203+
environment: 'TESTNET',
204+
addressDetailsType: AddressDetailsType.CryptoAddress,
205+
addressDetails: {
206+
address: 'rMwLfriHeWf5NMjcNKVMkqg58v1LYVRGnY',
207+
},
208+
},
209+
}),
210+
signatures: [
211+
{
212+
name: 'identityKey',
213+
protected:
214+
'eiJKT1NFK0pTT04iLCJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCIsIm5hbWUiXSwiandrIjp7ImNydiI6InNlY3AyNTZrMSIsIngiOiI2S0dtcEF6WUhWUm9qVmU5UEpfWTVyZHltQ21kTy1xaVRHem1Edl9waUlvIiwieSI6ImhxS3Vnc1g3Vjk3eFRNLThCMTBONUQxcW44MUZWMjItM1p0TURXaXZfSnciLCJrdHkiOiJFQyIsImtpZCI6Im4zNlhTc0M1TjRnNUtCVzRBWXJ5d1ZtRE1kUWNEV1BJX0RfNUR1UlNhNDAifX0',
215+
signature: 'Z2V0IGxvdy4uIHdlaGVyIGV5b3UgZnJvbSBteSBib3kgYXNqZGFr',
216+
},
217+
],
218+
},
219+
],
220+
}
221+
// AND our expected error response
222+
const expectedErrorResponse = {
223+
statusCode: 400,
224+
error: 'Bad Request',
225+
message: 'Invalid JSON for protected payload (identity key).',
226+
}
227+
228+
// WHEN we make a PUT request to /users/ with the new information to update
229+
request(app.adminApiExpress)
230+
.put(`/users/${payId}`)
231+
.set('PayID-API-Version', payIdNextApiVersion)
232+
.send(userInformation)
233+
.expect('Content-Type', /json/u)
234+
// THEN We expect back a 400 - Bad Request, with the expected error response object
235+
.expect(HttpStatus.BadRequest, expectedErrorResponse, done)
236+
})
237+
238+
it('Throws BadRequest error on multiple identity keys per PayID', function (done): void {
239+
// GIVEN a user with a PayID known to exist on the PayID service
240+
const payId = 'johnwick$127.0.0.1'
241+
const userInformation = {
242+
payId,
243+
addresses: [],
244+
verifiedAddresses: [
245+
{
246+
payload: JSON.stringify({
247+
payId,
248+
payIdAddress: {
249+
paymentNetwork: 'XRPL',
250+
environment: 'TESTNET',
251+
addressDetailsType: AddressDetailsType.CryptoAddress,
252+
addressDetails: {
253+
address: 'rMwLfriHeWf5NMjcNKVMkqg58v1LYVRGnY',
254+
},
255+
},
256+
}),
257+
signatures: [
258+
{
259+
name: 'identityKey',
260+
protected:
261+
'eyJuYW1lIjoiaWRlbnRpdHlLZXkiLCJhbGciOiJFUzI1NksiLCJ0eXAiOiJKT1NFK0pTT04iLCJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCIsIm5hbWUiXSwiandrIjp7ImNydiI6InNlY3AyNTZrMSIsIngiOiI2S0dtcEF6WUhWUm9qVmU5UEpfWTVyZHltQ21kTy1xaVRHem1Edl9waUlvIiwieSI6ImhxS3Vnc1g3Vjk3eFRNLThCMTBONUQxcW44MUZWMjItM1p0TURXaXZfSnciLCJrdHkiOiJFQyIsImtpZCI6Im4zNlhTc0M1TjRnNUtCVzRBWXJ5d1ZtRE1kUWNEV1BJX0RfNUR1UlNhNDAifX0',
262+
signature: 'Z2V0IGxvdy4uIHdlaGVyIGV5b3UgZnJvbSBteSBib3kgYXNqZGFr',
263+
},
264+
],
265+
},
266+
{
267+
payload: JSON.stringify({
268+
payId,
269+
payIdAddress: {
270+
paymentNetwork: 'XRPL',
271+
environment: 'MAINNET',
272+
addressDetailsType: AddressDetailsType.CryptoAddress,
273+
addressDetails: {
274+
address: 'rsem3MPogcwLCD6iX34GQ4fAp4EC8kqMYM',
275+
},
276+
},
277+
}),
278+
signatures: [
279+
{
280+
name: 'identityKey',
281+
protected:
282+
'eyJuYW1lIjoiaWRlbnRpdHlLZXkiLCJhbGciOiJFUzI1NksiLCJ0eXAiOiJKT1NFK0pTT04iLCJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCIsIm5hbWUiXSwiandrIjp7ImNydiI6InNlY3AyNTZrMSIsIngiOiJKcXNXZk1QSmNsU1JISWRtS3U0cl84MktPRXdERjctOU1XeWFYcjNkSGl3IiwieSI6IkMxZm5sQndUMmZtNzN1OGxweEhlc0NiX0xobEx2aktoeTRGN05ZdWpDR0EiLCJrdHkiOiJFQyIsImtpZCI6IlRZSlNCb05FSDVHYzVDQ0hyc3pfMVM0RHhwNk9SZVhIWlQ5bmZiYXQ3YTAifX0',
283+
signature: 'Z2V0IGxvdy4uIHdlaGVyIGV5b3UgZnJvbSBteSBib3kgYXNqZGFr',
284+
},
285+
],
286+
},
287+
],
288+
}
289+
290+
// AND our expected error response
291+
const expectedErrorResponse = {
292+
statusCode: 400,
293+
error: 'Bad Request',
294+
message:
295+
'More than one identity key detected. Only one identity key per PayID can be used.',
296+
}
297+
298+
// WHEN we make a PUT request to /users/ with the new information to update
299+
request(app.adminApiExpress)
300+
.put(`/users/${payId}`)
301+
.set('PayID-API-Version', payIdNextApiVersion)
302+
.send(userInformation)
303+
.expect('Content-Type', /json/u)
304+
// THEN We expect back a 400 - Bad Request, with the expected error response object
305+
.expect(HttpStatus.BadRequest, expectedErrorResponse, done)
306+
})
307+
308+
it('Throws BadRequest error on multiple identity keys per address', function (done): void {
309+
// GIVEN a user with a PayID known to exist on the PayID service
310+
const payId = 'verified$127.0.0.1'
311+
const userInformation = {
312+
payId,
313+
addresses: [],
314+
verifiedAddresses: [
315+
{
316+
payload: JSON.stringify({
317+
payId,
318+
payIdAddress: {
319+
paymentNetwork: 'XRPL',
320+
environment: 'TESTNET',
321+
addressDetailsType: AddressDetailsType.CryptoAddress,
322+
addressDetails: {
323+
address: 'rMwLfriHeWf5NMjcNKVMkqg58v1LYVRGnY',
324+
},
325+
},
326+
}),
327+
signatures: [
328+
{
329+
name: 'identityKey',
330+
protected:
331+
'eyJuYW1lIjoiaWRlbnRpdHlLZXkiLCJhbGciOiJFUzI1NksiLCJ0eXAiOiJKT1NFK0pTT04iLCJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCIsIm5hbWUiXSwiandrIjp7ImNydiI6InNlY3AyNTZrMSIsIngiOiI2S0dtcEF6WUhWUm9qVmU5UEpfWTVyZHltQ21kTy1xaVRHem1Edl9waUlvIiwieSI6ImhxS3Vnc1g3Vjk3eFRNLThCMTBONUQxcW44MUZWMjItM1p0TURXaXZfSnciLCJrdHkiOiJFQyIsImtpZCI6Im4zNlhTc0M1TjRnNUtCVzRBWXJ5d1ZtRE1kUWNEV1BJX0RfNUR1UlNhNDAifX0',
332+
signature: 'Z2V0IGxvdy4uIHdlaGVyIGV5b3UgZnJvbSBteSBib3kgYXNqZGFr',
333+
},
334+
{
335+
name: 'identityKey',
336+
protected:
337+
'eyJuYW1lIjoiaWRlbnRpdHlLZXkiLCJhbGciOiJFUzI1NksiLCJ0eXAiOiJKT1NFK0pTT04iLCJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCIsIm5hbWUiXSwiandrIjp7ImNydiI6InNlY3AyNTZrMSIsIngiOiI2S0dtcEF6WUhWUm9qVmU5UEpfWTVyZHltQ21kTy1xaVRHem1Edl9waUlvIiwieSI6ImhxS3Vnc1g3Vjk3eFRNLThCMTBONUQxcW44MUZWMjItM1p0TURXaXZfSnciLCJrdHkiOiJFQyIsImtpZCI6Im4zNlhTc0M1TjRnNUtCVzRBWXJ5d1ZtRE1kUWNEV1BJX0RfNUR1UlNhNDAifX0',
338+
signature: 'd2Fsa2luZyB0aG91Z2ggdGhlIHNyZWV3dCB3aWggbXkgdDQ0',
339+
},
340+
],
341+
},
342+
],
343+
}
344+
345+
// AND our expected error response
346+
const expectedErrorResponse = {
347+
statusCode: 400,
348+
error: 'Bad Request',
349+
message:
350+
'More than one identity key detected. Only one identity key per address can be used.',
351+
}
352+
353+
// WHEN we make a PUT request to /users/ with the new information to update
354+
request(app.adminApiExpress)
355+
.put(`/users/${payId}`)
356+
.set('PayID-API-Version', payIdNextApiVersion)
357+
.send(userInformation)
358+
.expect('Content-Type', /json/u)
359+
// THEN We expect back a 400 - Bad Request, with the expected error response object
360+
.expect(HttpStatus.BadRequest, expectedErrorResponse, done)
361+
})
362+
125363
it('Returns a 201 and inserted user payload for a Admin API PUT creating a new user', function (done): void {
126364
// GIVEN a PayID known to not exist on the PayID service
127365
const payId = 'notjohndoe$xpring.money'

0 commit comments

Comments
 (0)