Skip to content

Commit

Permalink
fix: update execute logic for __call
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinCK committed Apr 15, 2019
1 parent 1abcbff commit f105e52
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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;
let call: object;

/* istanbul ignore else */
if (data.__call) {
Expand All @@ -29,6 +29,21 @@ export class Builder {
delete data.__call;
}

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

if (fixture.processor) {
const processorPathWithoutExtension = path.join(
path.dirname(fixture.processor),
Expand All @@ -52,26 +67,15 @@ export class Builder {
}

Object.assign(entity, data);

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

/* istanbul ignore else */
if (typeof processorInstance.postProcess === 'function') {
await processorInstance.postProcess(fixture.name, entity);
}
} else {
Object.assign(entity, data);
callExecutors();
}

this.entities[fixture.name] = entity;
Expand Down

0 comments on commit f105e52

Please sign in to comment.