diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index 45dedc2f8..f265db41f 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -1,3 +1,7 @@ +unreleased: + fixed bugs: + - GH-1366 Fixed a bug where $randomAvatarImage was returning an invalid URL + 4.4.0: date: 2024-02-28 new features: diff --git a/lib/superstring/dynamic-variables.js b/lib/superstring/dynamic-variables.js index aeff852b4..d026487c7 100644 --- a/lib/superstring/dynamic-variables.js +++ b/lib/superstring/dynamic-variables.js @@ -371,7 +371,14 @@ var faker = require('@faker-js/faker/locale/en'), $randomAvatarImage: { description: 'A random avatar image', - generator: faker.image.avatar + generator: () => { + // ref: https://github.com/faker-js/faker/blob/v8.4.1/src/modules/image/index.ts#L61 + return faker.random.arrayElement([ + // eslint-disable-next-line max-len + `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/${faker.datatype.number(1249)}.jpg`, + `https://avatars.githubusercontent.com/u/${faker.datatype.number(100000000)}` + ]); + } }, $randomImageUrl: { description: 'A URL for a random image', diff --git a/test/unit/dynamic-variables.test.js b/test/unit/dynamic-variables.test.js index 9d0ac370e..5a7c5bc25 100644 --- a/test/unit/dynamic-variables.test.js +++ b/test/unit/dynamic-variables.test.js @@ -97,5 +97,12 @@ describe('Dynamic variable', function () { expect(directoryPath).to.not.be.undefined; expect(directoryPath).to.not.be.null; }); + + it('$randomAvatarImage returns a random avatar image', function () { + var avatarImage = dynamicVariables.$randomAvatarImage.generator(); + + expect(avatarImage).to.be.a('string') + .and.match(/^https:\/\/(avatars\.githubusercontent\.com|cloudflare-ipfs\.com)\/.+/); + }); }); });