From 4efaeb51aa78431dc2a01b716f214e15927a6a06 Mon Sep 17 00:00:00 2001 From: Udit Vasu Date: Mon, 29 Jul 2024 11:45:05 +0530 Subject: [PATCH] Fix test --- CHANGELOG.yaml | 6 ++---- lib/superstring/dynamic-variables.js | 11 ++++++----- test/unit/dynamic-variables.test.js | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index e36982952..f265db41f 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -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 diff --git a/lib/superstring/dynamic-variables.js b/lib/superstring/dynamic-variables.js index 2bfcb6434..7dc816c85 100644 --- a/lib/superstring/dynamic-variables.js +++ b/lib/superstring/dynamic-variables.js @@ -76,9 +76,11 @@ var faker = require('@faker-js/faker/locale/en'), ], /** - * Copied over from: https://github.com/faker-js/faker/blob/next/src/modules/image/index.ts#L27 * Generates a random avatar from GitHub. * + * Ref: https://github.com/faker-js/faker/blob/v8.4.1/src/modules/image/index.ts#L79 + * + * @private * @example 'https://avatars.githubusercontent.com/u/97165289' */ avatarGitHub = () => { @@ -86,10 +88,12 @@ var faker = require('@faker-js/faker/locale/en'), }, /** - * 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`. * + * Ref: https://github.com/faker-js/faker/blob/v8.4.1/src/modules/image/index.ts#L95 + * + * @private * @example 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/170.jpg' */ avatarLegacy = () => { @@ -394,9 +398,6 @@ 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 diff --git a/test/unit/dynamic-variables.test.js b/test/unit/dynamic-variables.test.js index 0e700ee1c..5a7c5bc25 100644 --- a/test/unit/dynamic-variables.test.js +++ b/test/unit/dynamic-variables.test.js @@ -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)\/.+/); }); }); });