|
| 1 | +import validator from 'validator'; |
1 | 2 | import { describe, expect, it } from 'vitest'; |
2 | 3 | import { faker } from '../../src'; |
3 | 4 | import { seededTests } from './../support/seededRuns'; |
@@ -38,6 +39,17 @@ describe('commerce', () => { |
38 | 39 | symbol: '$', |
39 | 40 | }); |
40 | 41 | }); |
| 42 | + |
| 43 | + t.describe('isbn', (t) => { |
| 44 | + t.it('noArgs') |
| 45 | + .it('with variant 10', 10) |
| 46 | + .it('with variant 13', 13) |
| 47 | + .it('with variant 10 and space separators', { |
| 48 | + variant: 10, |
| 49 | + separator: ' ', |
| 50 | + }) |
| 51 | + .it('with space separators', { separator: ' ' }); |
| 52 | + }); |
41 | 53 | }); |
42 | 54 |
|
43 | 55 | describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))( |
@@ -158,6 +170,60 @@ describe('commerce', () => { |
158 | 170 | ); |
159 | 171 | }); |
160 | 172 | }); |
| 173 | + |
| 174 | + describe(`isbn()`, () => { |
| 175 | + it('should return ISBN-13 with hyphen separators when not passing arguments', () => { |
| 176 | + const isbn = faker.commerce.isbn(); |
| 177 | + |
| 178 | + expect(isbn).toBeTruthy(); |
| 179 | + expect(isbn).toBeTypeOf('string'); |
| 180 | + expect( |
| 181 | + isbn, |
| 182 | + 'The expected match should be ISBN-13 with hyphens' |
| 183 | + ).toMatch(/^978-[01]-[\d-]{9}-\d$/); |
| 184 | + expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 13)); |
| 185 | + }); |
| 186 | + |
| 187 | + it('should return ISBN-10 with hyphen separators when passing variant 10 as argument', () => { |
| 188 | + const isbn = faker.commerce.isbn(10); |
| 189 | + |
| 190 | + expect( |
| 191 | + isbn, |
| 192 | + 'The expected match should be ISBN-10 with hyphens' |
| 193 | + ).toMatch(/^[01]-[\d-]{9}-[\dX]$/); |
| 194 | + expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 10)); |
| 195 | + }); |
| 196 | + |
| 197 | + it('should return ISBN-13 with hyphen separators when passing variant 13 as argument', () => { |
| 198 | + const isbn = faker.commerce.isbn(13); |
| 199 | + |
| 200 | + expect( |
| 201 | + isbn, |
| 202 | + 'The expected match should be ISBN-13 with hyphens' |
| 203 | + ).toMatch(/^978-[01]-[\d-]{9}-\d$/); |
| 204 | + expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 13)); |
| 205 | + }); |
| 206 | + |
| 207 | + it('should return ISBN-10 with space separators when passing variant 10 and space separators as argument', () => { |
| 208 | + const isbn = faker.commerce.isbn({ variant: 10, separator: ' ' }); |
| 209 | + |
| 210 | + expect( |
| 211 | + isbn, |
| 212 | + 'The expected match should be ISBN-10 with space separators' |
| 213 | + ).toMatch(/^[01] [\d ]{9} [\dX]$/); |
| 214 | + expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 10)); |
| 215 | + }); |
| 216 | + |
| 217 | + it('should return ISBN-13 with space separators when passing space separators as argument', () => { |
| 218 | + const isbn = faker.commerce.isbn({ separator: ' ' }); |
| 219 | + |
| 220 | + expect( |
| 221 | + isbn, |
| 222 | + 'The expected match should be ISBN-13 with space separators' |
| 223 | + ).toMatch(/^978 [01] [\d ]{9} \d$/); |
| 224 | + expect(isbn).toSatisfy((isbn: string) => validator.isISBN(isbn, 13)); |
| 225 | + }); |
| 226 | + }); |
161 | 227 | } |
162 | 228 | ); |
163 | 229 | }); |
0 commit comments