|
3 | 3 | 'use strict'
|
4 | 4 |
|
5 | 5 | const assert = require('assert')
|
6 |
| -const avatars = require('../lib/letter-avatars') |
| 6 | +const mock = require('mock-require') |
| 7 | + |
| 8 | +describe('generateAvatarURL() gravatar enabled', function () { |
| 9 | + let avatars |
| 10 | + beforeEach(function () { |
| 11 | + // Reset config to make sure we don't influence other tests |
| 12 | + let testconfig = { |
| 13 | + allowGravatar: true, |
| 14 | + serverURL: 'http://localhost:3000', |
| 15 | + port: 3000 |
| 16 | + } |
| 17 | + mock('../lib/config', testconfig) |
| 18 | + avatars = mock.reRequire('../lib/letter-avatars') |
| 19 | + }) |
7 | 20 |
|
8 |
| -describe('generateAvatarURL()', function () { |
9 | 21 | it('should return correct urls', function () {
|
10 | 22 | assert.strictEqual(avatars.generateAvatarURL('Daan Sprenkels', '[email protected]', true), 'https://www.gravatar.com/avatar/d41b5f3508cc3f31865566a47dd0336b?s=400')
|
11 | 23 | assert.strictEqual(avatars.generateAvatarURL('Daan Sprenkels', '[email protected]', false), 'https://www.gravatar.com/avatar/d41b5f3508cc3f31865566a47dd0336b?s=96')
|
12 | 24 | })
|
| 25 | + |
| 26 | + it('should return correct urls for names with spaces', function () { |
| 27 | + assert.strictEqual(avatars.generateAvatarURL('Daan Sprenkels'), 'http://localhost:3000/user/Daan%20Sprenkels/avatar.svg') |
| 28 | + }) |
| 29 | +}) |
| 30 | + |
| 31 | +describe('generateAvatarURL() gravatar disabled', function () { |
| 32 | + let avatars |
| 33 | + beforeEach(function () { |
| 34 | + // Reset config to make sure we don't influence other tests |
| 35 | + let testconfig = { |
| 36 | + allowGravatar: false, |
| 37 | + serverURL: 'http://localhost:3000', |
| 38 | + port: 3000 |
| 39 | + } |
| 40 | + mock('../lib/config', testconfig) |
| 41 | + avatars = mock.reRequire('../lib/letter-avatars') |
| 42 | + }) |
| 43 | + |
| 44 | + it('should return correct urls', function () { |
| 45 | + assert.strictEqual(avatars.generateAvatarURL('Daan Sprenkels', '[email protected]', true), 'http://localhost:3000/user/Daan%20Sprenkels/avatar.svg') |
| 46 | + assert.strictEqual(avatars.generateAvatarURL('Daan Sprenkels', '[email protected]', false), 'http://localhost:3000/user/Daan%20Sprenkels/avatar.svg') |
| 47 | + }) |
| 48 | + |
| 49 | + it('should return correct urls for names with spaces', function () { |
| 50 | + assert.strictEqual(avatars.generateAvatarURL('Daan Sprenkels'), 'http://localhost:3000/user/Daan%20Sprenkels/avatar.svg') |
| 51 | + }) |
13 | 52 | })
|
0 commit comments