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

refactor(parser): change faker methods (that were deprecated) to new version #56

Merged
merged 1 commit into from
Jul 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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