Skip to content

Commit

Permalink
fix(builder): call methods
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinCK committed Jan 10, 2019
1 parent f3cdc77 commit ca05906
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@ export class Builder {
const repository = this.connection.getRepository(fixture.entity);
const entity = repository.create();
let data = this.parser.parse(fixture.data, fixture, this.entities);
let call;

if (data.__call) {
if (typeof data.__call !== 'object') {
if (typeof data.__call !== 'object' || data.__call === null) {
throw new Error('invalid "__call" parameter format');
}

for (const [method, values] of Object.entries(data.__call)) {
if ((entity as any)[method]) {
(entity as any)[method].call(
entity,
this.parser.parse(values instanceof Array ? values : [values], fixture, this.entities),
);
}
}

call = data.__call;
delete data.__call;
}

Expand Down Expand Up @@ -58,6 +51,18 @@ export class Builder {

Object.assign(entity, data);

/* istanbul ignore else */
if (call) {
for (const [method, values] of Object.entries(call)) {
if ((entity as any)[method]) {
(entity as any)[method].apply(
entity,
this.parser.parse(values instanceof Array ? values : [values], fixture, this.entities),
);
}
}
}

/* istanbul ignore else */
if (typeof processorInstance.postProcess === 'function') {
processorInstance.postProcess(fixture.name, entity);
Expand Down

0 comments on commit ca05906

Please sign in to comment.