Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
codenirvana committed Jul 29, 2024
1 parent dc49d68 commit baf81f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 36 deletions.
6 changes: 2 additions & 4 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
unreleased:
fixed-bug:
- >-
GH-1366 Fixed a bug where $randomAvatarImage was returning an invalid URL.
fixed bugs:
- GH-1366 Fixed a bug where $randomAvatarImage was returning an invalid URL

4.4.0:
date: 2024-02-28
Expand Down
35 changes: 5 additions & 30 deletions lib/superstring/dynamic-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,6 @@ var faker = require('@faker-js/faker/locale/en'),
'/var/yp'
],

/**
* Copied over from: https://github.com/faker-js/faker/blob/next/src/modules/image/index.ts#L27
* Generates a random avatar from GitHub.
*
* @example 'https://avatars.githubusercontent.com/u/97165289'
*/
avatarGitHub = () => {
return `https://avatars.githubusercontent.com/u/${faker.datatype.number(100000000)}`;
},

/**
* Copied over from: https://github.com/faker-js/faker/blob/next/src/modules/image/index.ts#L27
* Generates a random avatar from
* `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar`.
*
* @example 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/170.jpg'
*/
avatarLegacy = () => {
// eslint-disable-next-line max-len
return `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/${faker.datatype.number(1249)}.jpg`;
},

// generators for $random* variables
dynamicGenerators = {
$guid: {
Expand Down Expand Up @@ -394,15 +372,12 @@ var faker = require('@faker-js/faker/locale/en'),
$randomAvatarImage: {
description: 'A random avatar image',
generator: () => {
// We have overridden the avatar generator to be similar to current
// latest version (v9) of faker.js. We don't want to upgrade to the latest
// version of faker.js as it is significantly big in size.
const avatarMethod = faker.random.arrayElement([
avatarLegacy,
avatarGitHub
// 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)}`
]);

return avatarMethod();
}
},
$randomImageUrl: {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/dynamic-variables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ describe('Dynamic variable', function () {
it('$randomAvatarImage returns a random avatar image', function () {
var avatarImage = dynamicVariables.$randomAvatarImage.generator();

expect(avatarImage).to.not.be.undefined;
expect(avatarImage).to.not.be.null;
expect(avatarImage).to.be.a('string')
.and.match(/^https:\/\/(avatars\.githubusercontent\.com|cloudflare-ipfs\.com)\/.+/);
});
});
});

0 comments on commit baf81f1

Please sign in to comment.