mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	test: added test for external image via new change picture API
This commit is contained in:
		| @@ -10,6 +10,16 @@ const utils = require('../../public/src/utils'); | ||||
|  | ||||
| const helpers = module.exports; | ||||
|  | ||||
| helpers.getCsrfToken = async (jar) => { | ||||
| 	const { csrf_token: token } = await requestAsync({ | ||||
| 		url: `${nconf.get('url')}/api/config`, | ||||
| 		json: true, | ||||
| 		jar, | ||||
| 	}); | ||||
|  | ||||
| 	return token; | ||||
| }; | ||||
|  | ||||
| helpers.loginUser = function (username, password, callback) { | ||||
| 	const jar = request.jar(); | ||||
|  | ||||
|   | ||||
							
								
								
									
										23
									
								
								test/user.js
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								test/user.js
									
									
									
									
									
								
							| @@ -5,6 +5,7 @@ const async = require('async'); | ||||
| const fs = require('fs'); | ||||
| const path = require('path'); | ||||
| const nconf = require('nconf'); | ||||
| const validator = require('validator'); | ||||
| const request = require('request'); | ||||
| const requestAsync = require('request-promise-native'); | ||||
| const jwt = require('jsonwebtoken'); | ||||
| @@ -1070,6 +1071,28 @@ describe('User', () => { | ||||
| 			}); | ||||
| 		}); | ||||
|  | ||||
| 		it('should let you set an external image', async () => { | ||||
| 			const token = await helpers.getCsrfToken(jar); | ||||
| 			const body = await requestAsync(`${nconf.get('url')}/api/v3/users/${uid}/picture`, { | ||||
| 				jar, | ||||
| 				method: 'put', | ||||
| 				json: true, | ||||
| 				headers: { | ||||
| 					'x-csrf-token': token, | ||||
| 				}, | ||||
| 				body: { | ||||
| 					type: 'external', | ||||
| 					url: 'https://example.org/picture.jpg', | ||||
| 				}, | ||||
| 			}); | ||||
|  | ||||
| 			assert(body && body.status && body.response); | ||||
| 			assert.strictEqual(body.status.code, 'ok'); | ||||
|  | ||||
| 			const picture = await User.getUserField(uid, 'picture'); | ||||
| 			assert.strictEqual(picture, validator.escape('https://example.org/picture.jpg')); | ||||
| 		}); | ||||
|  | ||||
| 		it('should fail to change user picture with invalid data', (done) => { | ||||
| 			socketUser.changePicture({ uid: uid }, null, (err) => { | ||||
| 				assert.equal(err.message, '[[error:invalid-data]]'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user