|
1 | 1 | import { pointy } from '../../../../src'; |
2 | 2 | const http = pointy.http; |
3 | 3 |
|
4 | | -describe('User API Update', () => {}); |
| 4 | +describe('User API Update', () => { |
| 5 | + beforeAll(async () => { |
| 6 | + this.user1 = await http |
| 7 | + .post('/api/v1/user', { |
| 8 | + fname: 'userPut', |
| 9 | + lname: 'userPut', |
| 10 | + username: 'userPut1', |
| 11 | + password: 'password123', |
| 12 | + email: 'userPut1@test.com' |
| 13 | + }) |
| 14 | + .catch((error) => |
| 15 | + fail('Could not create base user: ' + JSON.stringify(error)) |
| 16 | + ); |
| 17 | + }); |
| 18 | + |
| 19 | + it('can update', () => { |
| 20 | + http |
| 21 | + .put( |
| 22 | + `/api/v1/user/${this.user1.body.id}`, |
| 23 | + { |
| 24 | + lname: 'testLast' |
| 25 | + }, |
| 26 | + [ 204 ] |
| 27 | + ) |
| 28 | + .then((result) => { |
| 29 | + http |
| 30 | + .get( |
| 31 | + `/api/v1/user`, |
| 32 | + { |
| 33 | + id: this.user1.body.id |
| 34 | + }, |
| 35 | + [ 200 ] |
| 36 | + ) |
| 37 | + .then((getResult) => |
| 38 | + expect(getResult.body['lname']).toEqual('testLast') |
| 39 | + ) |
| 40 | + .catch((error) => fail(error)); |
| 41 | + }) |
| 42 | + .catch((error) => fail(error)); |
| 43 | + }); |
| 44 | + |
| 45 | + it('maintains other fields on update', () => { |
| 46 | + http |
| 47 | + .put( |
| 48 | + `/api/v1/user/${this.user1.body.id}`, |
| 49 | + { |
| 50 | + lname: 'testLast' |
| 51 | + }, |
| 52 | + [ 204 ] |
| 53 | + ) |
| 54 | + .then((result) => { |
| 55 | + http |
| 56 | + .get( |
| 57 | + `/api/v1/user`, |
| 58 | + { |
| 59 | + id: this.user1.body.id |
| 60 | + }, |
| 61 | + [ 200 ] |
| 62 | + ) |
| 63 | + .then((getResult) => |
| 64 | + expect(getResult.body['email']).toEqual( |
| 65 | + 'userPut1@test.com' |
| 66 | + ) |
| 67 | + ) |
| 68 | + .catch((error) => fail(error)); |
| 69 | + }) |
| 70 | + .catch((error) => fail(error)); |
| 71 | + }); |
| 72 | + |
| 73 | + it('cannot accept a nonsense username', async () => { |
| 74 | + await http |
| 75 | + .put( |
| 76 | + `/api/v1/user/${this.user1.body.id}`, |
| 77 | + { |
| 78 | + username: 'tom<tester5' |
| 79 | + }, |
| 80 | + [ 400 ] |
| 81 | + ) |
| 82 | + .catch((error) => fail(error)); |
| 83 | + }); |
| 84 | + |
| 85 | + it('cannot accept a nonsense email', async () => { |
| 86 | + await http |
| 87 | + .put( |
| 88 | + `/api/v1/user/${this.user1.body.id}`, |
| 89 | + { |
| 90 | + email: 'drew3test.com' |
| 91 | + }, |
| 92 | + [ 400 ] |
| 93 | + ) |
| 94 | + .catch((error) => fail(error)); |
| 95 | + }); |
| 96 | +}); |
0 commit comments