Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(unsplash.avatar): deprecate #1062

Merged
merged 10 commits into from
Jun 16, 2022
12 changes: 11 additions & 1 deletion src/modules/image/providers/unsplash.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Faker } from '../../..';
import { deprecated } from '../../../internal/deprecated';

/**
* Module to generate links to random images on `https://source.unsplash.com/`.
Expand Down Expand Up @@ -30,12 +31,21 @@ export class Unsplash {
/**
* Returns a random avatar url.
*
* @see faker.image.avatar
*
* @example
* faker.internet.avatar()
* // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/315.jpg'
*
* @deprecated
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
*/
// TODO ST-DDT 2022-03-11: Deprecate this method as it is duplicate and has nothing to do with unsplash.
avatar(): string {
deprecated({
deprecated: 'faker.image.unsplash.avatar()',
proposed: 'faker.image.avatar()',
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved
since: 'v7.3.0',
until: 'v8.0.0',
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
});
return this.faker.internet.avatar();
}

Expand Down
18 changes: 17 additions & 1 deletion test/image.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import { faker } from '../src';

describe('image', () => {
Expand Down Expand Up @@ -216,6 +216,22 @@ describe('image', () => {
});
});

describe('avatar()', () => {
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved
it('should log a deprecation message', () => {
const consoleSpy = vi.spyOn(console, 'warn');

faker.image.unsplash.avatar();

expect(consoleSpy).toHaveBeenCalled();

const logMessage = consoleSpy.mock.calls[0][0];
expect(logMessage).toContain('faker.image.unsplash.avatar()');
expect(logMessage).toContain('faker.image.avatar()');
expect(logMessage).toContain('v7.3.0');
expect(logMessage).toContain('v8.0.0');
});
});

const categories = [
'buildings',
'food',
Expand Down