diff options
| author | Guilherme Minozzi <[email protected]> | 2022-07-22 00:04:44 -0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-07-22 05:04:44 +0200 |
| commit | 3afc793f5b54fe3095d66f4e95af81e3e5a428d9 (patch) | |
| tree | cbd06a1e3a7cecdc5e4fbb06cb51a3915dd0f474 | |
| parent | fbddaa39e830e1ac44e7821d219ca7859af79e95 (diff) | |
| download | faker-3afc793f5b54fe3095d66f4e95af81e3e5a428d9.tar.xz faker-3afc793f5b54fe3095d66f4e95af81e3e5a428d9.zip | |
refactor(company): rename companyName to name (#1166)
| -rw-r--r-- | src/modules/company/index.ts | 28 | ||||
| -rw-r--r-- | src/modules/finance/index.ts | 2 | ||||
| -rw-r--r-- | test/__snapshots__/company.spec.ts.snap | 6 | ||||
| -rw-r--r-- | test/company.spec.ts | 35 |
4 files changed, 68 insertions, 3 deletions
diff --git a/src/modules/company/index.ts b/src/modules/company/index.ts index fb5f2e66..968afbbf 100644 --- a/src/modules/company/index.ts +++ b/src/modules/company/index.ts @@ -1,4 +1,5 @@ import type { Faker } from '../..'; +import { deprecated } from '../../internal/deprecated'; /** * Module to generate company related entries. @@ -31,9 +32,9 @@ export class Company { * @param format The optional format index used to select a format. * * @example - * faker.company.companyName() // 'Zieme, Hauck and McClure' + * faker.company.name() // 'Zieme, Hauck and McClure' */ - companyName(format?: number): string { + name(format?: number): string { const formats = [ '{{name.lastName}} {{company.companySuffix}}', '{{name.lastName}} - {{name.lastName}}', @@ -48,6 +49,29 @@ export class Company { } /** + * Generates a random company name. + * + * @param format The optional format index used to select a format. + * + * @see faker.company.name + * + * @example + * faker.company.companyName() // 'Zieme, Hauck and McClure' + * + * @deprecated Use `faker.company.name()` instead + */ + companyName(format?: number): string { + deprecated({ + deprecated: 'faker.company.companyName()', + proposed: 'faker.company.name()', + since: '7.4', + until: '8.0', + }); + + return this.name(format); + } + + /** * Returns a random company suffix. * * @example diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index ff9ffc68..5d83963b 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -424,7 +424,7 @@ export class Finance { */ transactionDescription(): string { const amount = this.amount(); - const company = this.faker.company.companyName(); + const company = this.faker.company.name(); const transactionType = this.transactionType(); const account = this.account(); const card = this.mask(); diff --git a/test/__snapshots__/company.spec.ts.snap b/test/__snapshots__/company.spec.ts.snap index f4dfd000..4e315ed3 100644 --- a/test/__snapshots__/company.spec.ts.snap +++ b/test/__snapshots__/company.spec.ts.snap @@ -20,6 +20,8 @@ exports[`company > seed: 42 > companyName() 1`] = `"Schinner - Wiegand"`; exports[`company > seed: 42 > companySuffix() 1`] = `"and Sons"`; +exports[`company > seed: 42 > name() 1`] = `"Schinner - Wiegand"`; + exports[`company > seed: 42 > suffixes() 1`] = ` [ "Inc", @@ -49,6 +51,8 @@ exports[`company > seed: 1211 > companyName() 1`] = `"Koch, Trantow and Sanford" exports[`company > seed: 1211 > companySuffix() 1`] = `"Group"`; +exports[`company > seed: 1211 > name() 1`] = `"Koch, Trantow and Sanford"`; + exports[`company > seed: 1211 > suffixes() 1`] = ` [ "Inc", @@ -78,6 +82,8 @@ exports[`company > seed: 1337 > companyName() 1`] = `"Macejkovic Inc"`; exports[`company > seed: 1337 > companySuffix() 1`] = `"and Sons"`; +exports[`company > seed: 1337 > name() 1`] = `"Macejkovic Inc"`; + exports[`company > seed: 1337 > suffixes() 1`] = ` [ "Inc", diff --git a/test/company.spec.ts b/test/company.spec.ts index b0f20792..a34bcafb 100644 --- a/test/company.spec.ts +++ b/test/company.spec.ts @@ -7,6 +7,7 @@ const NON_SEEDED_BASED_RUN = 5; const functionNames = [ 'suffixes', 'companyName', + 'name', 'companySuffix', 'catchPhrase', 'bs', @@ -50,6 +51,40 @@ describe('company', () => { }); }); + describe('name()', () => { + it('should return a random company name', () => { + const actual = faker.company.name(); + + expect(actual).toBeTruthy(); + expect(actual).toBeTypeOf('string'); + }); + + it('should return a random company name with format 0', () => { + const actual = faker.company.name(0); + + expect(actual).toBeTruthy(); + expect(actual).toBeTypeOf('string'); + expect(actual).includes(' '); + }); + + it('should return a random company name with format 1', () => { + const actual = faker.company.name(1); + + expect(actual).toBeTruthy(); + expect(actual).toBeTypeOf('string'); + expect(actual).includes(' - '); + }); + + it('should return a random company name with format 2', () => { + const actual = faker.company.name(2); + + expect(actual).toBeTruthy(); + expect(actual).toBeTypeOf('string'); + expect(actual).includes(', '); + expect(actual).includes(' and '); + }); + }); + describe('companyName()', () => { it('should return a random company name', () => { const actual = faker.company.companyName(); |
