Skip to content

Commit

Permalink
refactor(parser): change faker methods (that were deprecated) to new …
Browse files Browse the repository at this point in the history
…version
  • Loading branch information
omermorad committed Jul 18, 2021
1 parent cf56561 commit 8a6d9d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions packages/parser/src/handlers/array-value-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ describe('ArrayValueHandler Unit Test', () => {
const fakerMock = {
random: {
alpha: jest.fn().mockReturnValue('random-string'),
alphaNumeric: jest.fn(),
},
datatype: {
number: jest.fn(),
boolean: jest.fn(),
alphaNumeric: jest.fn(),
},
date: {
recent: jest.fn(),
Expand Down Expand Up @@ -81,8 +83,8 @@ describe('ArrayValueHandler Unit Test', () => {
});

test('then call random alpha string from faker', () => {
expect(fakerMock.random.number).toHaveBeenCalledTimes(DEFAULT_COUNT_FOR_DTO);
expect(fakerMock.random.number).toHaveBeenCalledWith(1000);
expect(fakerMock.datatype.number).toHaveBeenCalledTimes(DEFAULT_COUNT_FOR_DTO);
expect(fakerMock.datatype.number).toHaveBeenCalledWith(1000);
});

test("then return an array of 'count' numbers", () => {
Expand All @@ -94,7 +96,7 @@ describe('ArrayValueHandler Unit Test', () => {
describe('and the primitive decoratorValue is Boolean', () => {
test('and the primitive decoratorValue is Boolean', () => {
handler.produceValue(createProperty({ type: Boolean, count: DEFAULT_COUNT_FOR_DTO }));
expect(fakerMock.random.boolean).toHaveBeenCalledTimes(DEFAULT_COUNT_FOR_DTO);
expect(fakerMock.datatype.boolean).toHaveBeenCalledTimes(DEFAULT_COUNT_FOR_DTO);
});
});

Expand Down
4 changes: 2 additions & 2 deletions packages/parser/src/handlers/primitive-handler-abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export abstract class PrimitiveHandlerAbstract extends AbstractValueHandler {
if (ctor === 'String') {
return faker.random.alpha({ count: 10 });
} else if (ctor === 'Number') {
return faker.random.number(1000);
return faker.datatype.number(1000);
} else if (ctor === 'Boolean') {
return faker.random.boolean();
return faker.datatype.boolean();
} else if (ctor === 'Date') {
return faker.date.recent();
} else {
Expand Down
10 changes: 6 additions & 4 deletions packages/parser/src/handlers/primitive-value-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ describe('PrimitiveValueHandler Unit', () => {
const fakerMock = {
random: {
alpha: jest.fn(),
alphaNumeric: jest.fn(),
},
datatype: {
number: jest.fn(),
boolean: jest.fn(),
alphaNumeric: jest.fn(),
},
date: {
recent: jest.fn(),
Expand Down Expand Up @@ -83,16 +85,16 @@ describe('PrimitiveValueHandler Unit', () => {
const property = new Property('name', 'Number', new PropertyDecoratorValue(undefined));
handler.produceValue(property);

expect(fakerMock.random.number).toHaveBeenCalledTimes(1);
expect(fakerMock.random.number).toHaveBeenCalledWith(1000);
expect(fakerMock.datatype.number).toHaveBeenCalledTimes(1);
expect(fakerMock.datatype.number).toHaveBeenCalledWith(1000);
});
});

describe('and the constructor is a Boolean', () => {
test('then return random boolean decoratorValue', () => {
const property = new Property('name', 'Boolean', new PropertyDecoratorValue(undefined));
handler.produceValue(property);
expect(fakerMock.random.boolean).toHaveBeenCalledTimes(1);
expect(fakerMock.datatype.boolean).toHaveBeenCalledTimes(1);
});
});

Expand Down

0 comments on commit 8a6d9d4

Please sign in to comment.