aboutsummaryrefslogtreecommitdiff
path: root/test/modules
diff options
context:
space:
mode:
authorRobin van der Vliet <[email protected]>2023-09-10 10:05:56 +0200
committerGitHub <[email protected]>2023-09-10 10:05:56 +0200
commitcb4ef2846ad8d09cdc4ca5366b6057f9f6e38783 (patch)
tree52eed7018da3cb7e3c54c232d88fd002bbd482b5 /test/modules
parent8a6ce4978fada63f6364237e968f427e0a198135 (diff)
downloadfaker-cb4ef2846ad8d09cdc4ca5366b6057f9f6e38783.tar.xz
faker-cb4ef2846ad8d09cdc4ca5366b6057f9f6e38783.zip
feat(commerce): add method for generating ISBN-10 and ISBN-13 (#2240)
Diffstat (limited to 'test/modules')
-rw-r--r--test/modules/__snapshots__/commerce.spec.ts.snap30
-rw-r--r--test/modules/commerce.spec.ts66
2 files changed, 96 insertions, 0 deletions
diff --git a/test/modules/__snapshots__/commerce.spec.ts.snap b/test/modules/__snapshots__/commerce.spec.ts.snap
index 1dde6785..00b8f08e 100644
--- a/test/modules/__snapshots__/commerce.spec.ts.snap
+++ b/test/modules/__snapshots__/commerce.spec.ts.snap
@@ -2,6 +2,16 @@
exports[`commerce > 42 > department 1`] = `"Tools"`;
+exports[`commerce > 42 > isbn > noArgs 1`] = `"978-0-7917-7551-6"`;
+
+exports[`commerce > 42 > isbn > with space separators 1`] = `"978 0 7917 7551 6"`;
+
+exports[`commerce > 42 > isbn > with variant 10 1`] = `"0-7917-7551-8"`;
+
+exports[`commerce > 42 > isbn > with variant 10 and space separators 1`] = `"0 7917 7551 8"`;
+
+exports[`commerce > 42 > isbn > with variant 13 1`] = `"978-0-7917-7551-6"`;
+
exports[`commerce > 42 > price > noArgs 1`] = `"375.00"`;
exports[`commerce > 42 > price > with max 1`] = `"375.00"`;
@@ -36,6 +46,16 @@ exports[`commerce > 42 > productName 1`] = `"Fantastic Soft Sausages"`;
exports[`commerce > 1211 > department 1`] = `"Automotive"`;
+exports[`commerce > 1211 > isbn > noArgs 1`] = `"978-1-4872-1906-2"`;
+
+exports[`commerce > 1211 > isbn > with space separators 1`] = `"978 1 4872 1906 2"`;
+
+exports[`commerce > 1211 > isbn > with variant 10 1`] = `"1-4872-1906-7"`;
+
+exports[`commerce > 1211 > isbn > with variant 10 and space separators 1`] = `"1 4872 1906 7"`;
+
+exports[`commerce > 1211 > isbn > with variant 13 1`] = `"978-1-4872-1906-2"`;
+
exports[`commerce > 1211 > price > noArgs 1`] = `"929.00"`;
exports[`commerce > 1211 > price > with max 1`] = `"929.00"`;
@@ -70,6 +90,16 @@ exports[`commerce > 1211 > productName 1`] = `"Unbranded Cotton Salad"`;
exports[`commerce > 1337 > department 1`] = `"Computers"`;
+exports[`commerce > 1337 > isbn > noArgs 1`] = `"978-0-512-25403-0"`;
+
+exports[`commerce > 1337 > isbn > with space separators 1`] = `"978 0 512 25403 0"`;
+
+exports[`commerce > 1337 > isbn > with variant 10 1`] = `"0-512-25403-6"`;
+
+exports[`commerce > 1337 > isbn > with variant 10 and space separators 1`] = `"0 512 25403 6"`;
+
+exports[`commerce > 1337 > isbn > with variant 13 1`] = `"978-0-512-25403-0"`;
+
exports[`commerce > 1337 > price > noArgs 1`] = `"263.00"`;
exports[`commerce > 1337 > price > with max 1`] = `"263.00"`;
diff --git a/test/modules/commerce.spec.ts b/test/modules/commerce.spec.ts
index 15ad7aee..0588e228 100644
--- a/test/modules/commerce.spec.ts
+++ b/test/modules/commerce.spec.ts
@@ -1,3 +1,4 @@
+import validator from 'validator';
import { describe, expect, it } from 'vitest';
import { faker } from '../../src';
import { seededTests } from './../support/seededRuns';
@@ -38,6 +39,17 @@ describe('commerce', () => {
symbol: '$',
});
});
+
+ t.describe('isbn', (t) => {
+ t.it('noArgs')
+ .it('with variant 10', 10)
+ .it('with variant 13', 13)
+ .it('with variant 10 and space separators', {
+ variant: 10,
+ separator: ' ',
+ })
+ .it('with space separators', { separator: ' ' });
+ });
});
describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))(
@@ -158,6 +170,60 @@ describe('commerce', () => {
);
});
});
+
+ describe(`isbn()`, () => {
+ it('should return ISBN-13 with hyphen separators when not passing arguments', () => {
+ const isbn = faker.commerce.isbn();
+
+ expect(isbn).toBeTruthy();
+ expect(isbn).toBeTypeOf('string');
+ expect(
+ isbn,
+ 'The expected match should be ISBN-13 with hyphens'
+ ).toMatch(/^978-[01]-[\d-]{9}-\d$/);
+ expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 13));
+ });
+
+ it('should return ISBN-10 with hyphen separators when passing variant 10 as argument', () => {
+ const isbn = faker.commerce.isbn(10);
+
+ expect(
+ isbn,
+ 'The expected match should be ISBN-10 with hyphens'
+ ).toMatch(/^[01]-[\d-]{9}-[\dX]$/);
+ expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 10));
+ });
+
+ it('should return ISBN-13 with hyphen separators when passing variant 13 as argument', () => {
+ const isbn = faker.commerce.isbn(13);
+
+ expect(
+ isbn,
+ 'The expected match should be ISBN-13 with hyphens'
+ ).toMatch(/^978-[01]-[\d-]{9}-\d$/);
+ expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 13));
+ });
+
+ it('should return ISBN-10 with space separators when passing variant 10 and space separators as argument', () => {
+ const isbn = faker.commerce.isbn({ variant: 10, separator: ' ' });
+
+ expect(
+ isbn,
+ 'The expected match should be ISBN-10 with space separators'
+ ).toMatch(/^[01] [\d ]{9} [\dX]$/);
+ expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 10));
+ });
+
+ it('should return ISBN-13 with space separators when passing space separators as argument', () => {
+ const isbn = faker.commerce.isbn({ separator: ' ' });
+
+ expect(
+ isbn,
+ 'The expected match should be ISBN-13 with space separators'
+ ).toMatch(/^978 [01] [\d ]{9} \d$/);
+ expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 13));
+ });
+ });
}
);
});