Skip to content

Commit

Permalink
refactor(image): deprecate avatarLegacy (#3109)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Sep 20, 2024
1 parent f27f9c5 commit dfbf6c4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
19 changes: 12 additions & 7 deletions src/modules/image/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { deprecated } from '../../internal/deprecated';
import { ModuleBase } from '../../internal/module-base';

/**
Expand All @@ -24,12 +25,8 @@ export class ImageModule extends ModuleBase {
* @since 2.0.1
*/
avatar(): string {
const avatarMethod = this.faker.helpers.arrayElement([
this.avatarLegacy,
this.avatarGitHub,
]);

return avatarMethod();
// Add new avatar providers here, when adding a new one.
return this.avatarGitHub();
}

/**
Expand All @@ -55,9 +52,17 @@ export class ImageModule extends ModuleBase {
* // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/170.jpg'
*
* @since 8.0.0
*
* @deprecated The links are no longer working. Use `avatar()` instead.
*/
// This implementation will change in the future when we tackle https://github.com/faker-js/faker/issues/465.
avatarLegacy(): string {
deprecated({
deprecated: 'faker.image.avatarLegacy()',
proposed: 'faker.image.avatar()',
since: '9.0.1',
until: '10.0.0',
});

return `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/${this.faker.number.int(
1249
)}.jpg`;
Expand Down
6 changes: 3 additions & 3 deletions test/modules/__snapshots__/image.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`image > 42 > avatar 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/1188.jpg"`;
exports[`image > 42 > avatar 1`] = `"https://avatars.githubusercontent.com/u/37454012"`;

exports[`image > 42 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/37454012"`;

Expand Down Expand Up @@ -76,7 +76,7 @@ exports[`image > 42 > urlPlaceholder > with width 1`] = `"https://via.placeholde

exports[`image > 42 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/8ead33/1ddf0f.webp?text=benevolentia%20attonbitus%20auctus"`;

exports[`image > 1211 > avatar 1`] = `"https://avatars.githubusercontent.com/u/89347165"`;
exports[`image > 1211 > avatar 1`] = `"https://avatars.githubusercontent.com/u/92852016"`;

exports[`image > 1211 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/92852016"`;

Expand Down Expand Up @@ -152,7 +152,7 @@ exports[`image > 1211 > urlPlaceholder > with width 1`] = `"https://via.placehol

exports[`image > 1211 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/ed4fef/a7fbae.webp?text=dapifer%20usque%20unde"`;

exports[`image > 1337 > avatar 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/198.jpg"`;
exports[`image > 1337 > avatar 1`] = `"https://avatars.githubusercontent.com/u/26202467"`;

exports[`image > 1337 > avatarGitHub 1`] = `"https://avatars.githubusercontent.com/u/26202467"`;

Expand Down
1 change: 1 addition & 0 deletions test/modules/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe('image', () => {

describe('avatarLegacy', () => {
it('should return a random avatar url from cloudflare-ipfs', () => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const avatarUrl = faker.image.avatarLegacy();

expect(avatarUrl).toBeTypeOf('string');
Expand Down

0 comments on commit dfbf6c4

Please sign in to comment.