Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b46ece276e | ||
|
|
f5ba3146d7 |
@@ -4,7 +4,7 @@ import { Entity, EntityManager } from "data/entities";
|
|||||||
import {
|
import {
|
||||||
ManyToOneRelation,
|
ManyToOneRelation,
|
||||||
OneToOneRelation,
|
OneToOneRelation,
|
||||||
RelationField,
|
type RelationField,
|
||||||
RelationMutator,
|
RelationMutator,
|
||||||
} from "data/relations";
|
} from "data/relations";
|
||||||
import { NumberField, TextField } from "data/fields";
|
import { NumberField, TextField } from "data/fields";
|
||||||
@@ -41,6 +41,24 @@ describe("[data] Mutator (base)", async () => {
|
|||||||
|
|
||||||
// but expect additional fields to be present
|
// but expect additional fields to be present
|
||||||
expect((res.data as any).not_fillable).toBeDefined();
|
expect((res.data as any).not_fillable).toBeDefined();
|
||||||
|
expect((res.data as any).id).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("insertMany", async () => {
|
||||||
|
expect(em.mutator(entity).getValidatedData(payload, "create")).resolves.toEqual(payload);
|
||||||
|
const res = await em.mutator(entity).insertMany([
|
||||||
|
{ label: "item 1", count: 1 },
|
||||||
|
{ label: "item 2", count: 2 },
|
||||||
|
{ label: "item 3", count: 3 },
|
||||||
|
{ label: "item 4", count: 4 },
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(res.data.length).toBe(4);
|
||||||
|
res.data.forEach((entry) => {
|
||||||
|
expect((entry as any).id).toBeDefined();
|
||||||
|
expect((entry as any).label).toStartWith("item ");
|
||||||
|
expect(entry.count).toBeNumber();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("updateOne", async () => {
|
test("updateOne", async () => {
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ export class Mutator<
|
|||||||
|
|
||||||
const validated: any[] = [];
|
const validated: any[] = [];
|
||||||
for (const row of data) {
|
for (const row of data) {
|
||||||
const validatedData = {
|
let validatedData = {
|
||||||
...entity.getDefaultObject(),
|
...entity.getDefaultObject(),
|
||||||
...(await this.getValidatedData(row, "create")),
|
...(await this.getValidatedData(row, "create")),
|
||||||
};
|
};
|
||||||
@@ -328,6 +328,16 @@ export class Mutator<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// primary
|
||||||
|
const primary = entity.getPrimaryField();
|
||||||
|
const primary_value = primary.getNewValue();
|
||||||
|
if (primary_value) {
|
||||||
|
validatedData = {
|
||||||
|
[primary.name]: primary_value,
|
||||||
|
...validatedData,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
validated.push(validatedData);
|
validated.push(validatedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user