From 021bb38cf4c8f134ce46e595d54309c6d2890b76 Mon Sep 17 00:00:00 2001 From: Vedanta Krishna <37595282+vedkribhu@users.noreply.github.com> Date: Mon, 29 Jul 2024 11:56:10 +0530 Subject: [PATCH] fix the randomAvatar dynamic variable url returning 404 in faker.js (#1366) --- CHANGELOG.yaml | 4 ++++ lib/superstring/dynamic-variables.js | 9 ++++++++- test/unit/dynamic-variables.test.js | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) 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)\/.+/); + }); }); });