Skip to content

Commit

Permalink
fix the randomAvatar dynamic variable url returning 404 in faker.js (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vedkribhu authored Jul 29, 2024
1 parent e1dfe7a commit 021bb38
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
9 changes: 8 additions & 1 deletion lib/superstring/dynamic-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions test/unit/dynamic-variables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)\/.+/);
});
});
});

0 comments on commit 021bb38

Please sign in to comment.