typeorm-autofixtures 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/array-helper.d.ts +4 -0
- package/dist/array-helper.d.ts.map +1 -0
- package/dist/array-helper.js +9 -0
- package/dist/array-helper.js.map +1 -0
- package/dist/constructor-params.d.ts +7 -0
- package/dist/constructor-params.d.ts.map +1 -0
- package/dist/constructor-params.js +3 -0
- package/dist/constructor-params.js.map +1 -0
- package/dist/fixture-context.d.ts +17 -0
- package/dist/fixture-context.d.ts.map +1 -0
- package/dist/fixture-context.js +52 -0
- package/dist/fixture-context.js.map +1 -0
- package/dist/fixture-relation.helper.d.ts +22 -0
- package/dist/fixture-relation.helper.d.ts.map +1 -0
- package/dist/fixture-relation.helper.js +47 -0
- package/dist/fixture-relation.helper.js.map +1 -0
- package/dist/fixture.d.ts +40 -0
- package/dist/fixture.d.ts.map +1 -0
- package/dist/fixture.js +329 -0
- package/dist/fixture.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/valid-values.d.ts +2 -0
- package/dist/valid-values.d.ts.map +1 -0
- package/dist/valid-values.js +3 -0
- package/dist/valid-values.js.map +1 -0
- package/package.json +40 -0
- package/readme.md +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andre Carlucci
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-helper.d.ts","sourceRoot":"","sources":["../src/array-helper.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,WAAW;IAC9B,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS;CAGxC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ArrayHelper {
|
|
4
|
+
static last(arr) {
|
|
5
|
+
return arr.length > 0 ? arr[arr.length - 1] : undefined;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
exports.default = ArrayHelper;
|
|
9
|
+
//# sourceMappingURL=array-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-helper.js","sourceRoot":"","sources":["../src/array-helper.ts"],"names":[],"mappings":";;AAAA,MAAqB,WAAW;IAC9B,MAAM,CAAC,IAAI,CAAI,GAAQ;QACrB,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1D,CAAC;CACF;AAJD,8BAIC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type RequiredKeys<T> = {
|
|
2
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
3
|
+
}[keyof T];
|
|
4
|
+
type RequiredProps<T> = Pick<T, RequiredKeys<T>>;
|
|
5
|
+
export type ConstructorParams<T> = RequiredProps<T> & Partial<T>;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=constructor-params.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constructor-params.d.ts","sourceRoot":"","sources":["../src/constructor-params.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,CAAC,CAAC,IAAI;KACpB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;CACpD,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,KAAK,aAAa,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjD,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constructor-params.js","sourceRoot":"","sources":["../src/constructor-params.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class FixtureContext {
|
|
2
|
+
dictionary: TypeRegistry;
|
|
3
|
+
getLast<T>(type: Ctor<T>): T | undefined;
|
|
4
|
+
count<T>(type: Ctor<T>): number;
|
|
5
|
+
merge(otherContext: FixtureContext): void;
|
|
6
|
+
}
|
|
7
|
+
export type Ctor<T = object> = {
|
|
8
|
+
prototype: T;
|
|
9
|
+
};
|
|
10
|
+
export declare class TypeRegistry {
|
|
11
|
+
map: Map<Ctor<any>, any[]>;
|
|
12
|
+
set<T>(classReference: Ctor<T>, instances: T[]): void;
|
|
13
|
+
get<T>(classReference: Ctor<T>): T[] | undefined;
|
|
14
|
+
getOrCreate<T>(classReference: Ctor<T>, factory: () => T[]): T[];
|
|
15
|
+
merge(otherRegistry: TypeRegistry): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=fixture-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture-context.d.ts","sourceRoot":"","sources":["../src/fixture-context.ts"],"names":[],"mappings":"AAEA,qBAAa,cAAc;IAClB,UAAU,EAAE,YAAY,CAAsB;IAE9C,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS;IAKxC,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM;IAK/B,KAAK,CAAC,YAAY,EAAE,cAAc,GAAG,IAAI;CAGjD;AAED,MAAM,MAAM,IAAI,CAAC,CAAC,GAAG,MAAM,IAAI;IAAE,SAAS,EAAE,CAAC,CAAA;CAAE,CAAC;AAEhD,qBAAa,YAAY;IAChB,GAAG,wBAA+B;IAElC,GAAG,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,IAAI;IAIrD,GAAG,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS;IAIhD,WAAW,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,EAAE;IAUhE,KAAK,CAAC,aAAa,EAAE,YAAY,GAAG,IAAI;CAMhD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TypeRegistry = exports.FixtureContext = void 0;
|
|
7
|
+
const array_helper_1 = __importDefault(require("./array-helper"));
|
|
8
|
+
class FixtureContext {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.dictionary = new TypeRegistry();
|
|
11
|
+
}
|
|
12
|
+
getLast(type) {
|
|
13
|
+
const array = this.dictionary.get(type);
|
|
14
|
+
return array ? array_helper_1.default.last(array) : undefined;
|
|
15
|
+
}
|
|
16
|
+
count(type) {
|
|
17
|
+
const array = this.dictionary.get(type);
|
|
18
|
+
return array ? array.length : 0;
|
|
19
|
+
}
|
|
20
|
+
merge(otherContext) {
|
|
21
|
+
this.dictionary.merge(otherContext.dictionary);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.FixtureContext = FixtureContext;
|
|
25
|
+
class TypeRegistry {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.map = new Map();
|
|
28
|
+
}
|
|
29
|
+
set(classReference, instances) {
|
|
30
|
+
this.map.set(classReference, instances);
|
|
31
|
+
}
|
|
32
|
+
get(classReference) {
|
|
33
|
+
return this.map.get(classReference);
|
|
34
|
+
}
|
|
35
|
+
getOrCreate(classReference, factory) {
|
|
36
|
+
const existing = this.get(classReference);
|
|
37
|
+
if (existing) {
|
|
38
|
+
return existing;
|
|
39
|
+
}
|
|
40
|
+
const created = factory();
|
|
41
|
+
this.set(classReference, created);
|
|
42
|
+
return created;
|
|
43
|
+
}
|
|
44
|
+
merge(otherRegistry) {
|
|
45
|
+
for (const [key, value] of otherRegistry.map.entries()) {
|
|
46
|
+
const existingArray = this.getOrCreate(key, () => []);
|
|
47
|
+
existingArray.push(...value);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.TypeRegistry = TypeRegistry;
|
|
52
|
+
//# sourceMappingURL=fixture-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture-context.js","sourceRoot":"","sources":["../src/fixture-context.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAyC;AAEzC,MAAa,cAAc;IAA3B;QACS,eAAU,GAAiB,IAAI,YAAY,EAAE,CAAC;IAevD,CAAC;IAbQ,OAAO,CAAI,IAAa;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,CAAC,CAAC,sBAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACrD,CAAC;IAEM,KAAK,CAAI,IAAa;QAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;IAEM,KAAK,CAAC,YAA4B;QACvC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IACjD,CAAC;CACF;AAhBD,wCAgBC;AAID,MAAa,YAAY;IAAzB;QACS,QAAG,GAAG,IAAI,GAAG,EAAoB,CAAC;IA0B3C,CAAC;IAxBQ,GAAG,CAAI,cAAuB,EAAE,SAAc;QACnD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IAC1C,CAAC;IAEM,GAAG,CAAI,cAAuB;QACnC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAoB,CAAC;IACzD,CAAC;IAEM,WAAW,CAAI,cAAuB,EAAE,OAAkB;QAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1C,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC;QAC1B,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAClC,OAAO,OAAO,CAAC;IACjB,CAAC;IAEM,KAAK,CAAC,aAA2B;QACtC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;YACvD,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YACtD,aAAa,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;CACF;AA3BD,oCA2BC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EntityTarget } from "typeorm";
|
|
2
|
+
import { RelationMetadata } from "typeorm/metadata/RelationMetadata";
|
|
3
|
+
export declare class FixtureRelationHelper<T> {
|
|
4
|
+
relationType: "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many";
|
|
5
|
+
sourceTypeName: string;
|
|
6
|
+
sourceType: EntityTarget<any>;
|
|
7
|
+
sourcePropertyName: string;
|
|
8
|
+
isNullable: boolean;
|
|
9
|
+
targetPropertyName: string;
|
|
10
|
+
targetTypeName: string;
|
|
11
|
+
targetType: EntityTarget<any>;
|
|
12
|
+
instance: T;
|
|
13
|
+
providedValue: any;
|
|
14
|
+
constructor(instance: T, relation: RelationMetadata, providedValues: Partial<T>);
|
|
15
|
+
private getSourcePropertyName;
|
|
16
|
+
userProvidedValue(): boolean;
|
|
17
|
+
setInstanceProperty(value: any): void;
|
|
18
|
+
addValueToInstanceArray(value: any): void;
|
|
19
|
+
addThisInstanceToTheTargetSideArray(targetSide: any): void;
|
|
20
|
+
getLogMessage(suffix: string): string;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=fixture-relation.helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture-relation.helper.d.ts","sourceRoot":"","sources":["../src/fixture-relation.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,qBAAa,qBAAqB,CAAC,CAAC;IAC3B,YAAY,EAAE,YAAY,GAAG,aAAa,GAAG,aAAa,GAAG,cAAc,CAAC;IAC5E,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;IAC9B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;IAC9B,QAAQ,EAAE,CAAC,CAAC;IACZ,aAAa,EAAE,GAAG,CAAC;gBAEP,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;IAetF,OAAO,CAAC,qBAAqB;IAItB,iBAAiB,IAAI,OAAO;IAI5B,mBAAmB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAIrC,uBAAuB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAOzC,mCAAmC,CAAC,UAAU,EAAE,GAAG,GAAG,IAAI;IAS1D,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAK7C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FixtureRelationHelper = void 0;
|
|
4
|
+
class FixtureRelationHelper {
|
|
5
|
+
constructor(instance, relation, providedValues) {
|
|
6
|
+
this.relationType = relation.relationType;
|
|
7
|
+
this.sourceTypeName = relation.entityMetadata.name;
|
|
8
|
+
this.sourceType = relation.entityMetadata.target;
|
|
9
|
+
this.sourcePropertyName = relation.propertyName;
|
|
10
|
+
this.isNullable = relation.isNullable;
|
|
11
|
+
this.targetTypeName = relation.inverseEntityMetadata.name;
|
|
12
|
+
this.targetType = relation.inverseEntityMetadata.target;
|
|
13
|
+
this.targetPropertyName = relation.inverseRelation
|
|
14
|
+
? relation.inverseRelation.propertyName
|
|
15
|
+
: relation.inverseSidePropertyPath;
|
|
16
|
+
this.instance = instance;
|
|
17
|
+
this.providedValue = providedValues[this.getSourcePropertyName()];
|
|
18
|
+
}
|
|
19
|
+
getSourcePropertyName() {
|
|
20
|
+
return this.sourcePropertyName;
|
|
21
|
+
}
|
|
22
|
+
userProvidedValue() {
|
|
23
|
+
return this.providedValue !== undefined;
|
|
24
|
+
}
|
|
25
|
+
setInstanceProperty(value) {
|
|
26
|
+
this.instance[this.getSourcePropertyName()] = value;
|
|
27
|
+
}
|
|
28
|
+
addValueToInstanceArray(value) {
|
|
29
|
+
if (!this.instance[this.getSourcePropertyName()]) {
|
|
30
|
+
this.instance[this.getSourcePropertyName()] = [];
|
|
31
|
+
}
|
|
32
|
+
this.instance[this.getSourcePropertyName()].push(value);
|
|
33
|
+
}
|
|
34
|
+
addThisInstanceToTheTargetSideArray(targetSide) {
|
|
35
|
+
if (this.targetPropertyName) {
|
|
36
|
+
if (!targetSide[this.targetPropertyName]) {
|
|
37
|
+
targetSide[this.targetPropertyName] = [];
|
|
38
|
+
}
|
|
39
|
+
targetSide[this.targetPropertyName].push(this.instance);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
getLogMessage(suffix) {
|
|
43
|
+
return `${this.relationType.toUpperCase()} for ${this.sourceTypeName}.${this.sourcePropertyName} -> ${this.targetTypeName}.${this.targetPropertyName}: ${suffix}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.FixtureRelationHelper = FixtureRelationHelper;
|
|
47
|
+
//# sourceMappingURL=fixture-relation.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture-relation.helper.js","sourceRoot":"","sources":["../src/fixture-relation.helper.ts"],"names":[],"mappings":";;;AAGA,MAAa,qBAAqB;IAYhC,YAAmB,QAAW,EAAE,QAA0B,EAAE,cAA0B;QACpF,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;QAC1C,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC;QACnD,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,cAAc,CAAC,MAA2B,CAAC;QACtE,IAAI,CAAC,kBAAkB,GAAG,QAAQ,CAAC,YAAY,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC,qBAAqB,CAAC,IAAI,CAAC;QAC1D,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,qBAAqB,CAAC,MAA2B,CAAC;QAC7E,IAAI,CAAC,kBAAkB,GAAG,QAAQ,CAAC,eAAe;YAChD,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,YAAY;YACvC,CAAC,CAAC,QAAQ,CAAC,uBAAuB,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,cAAc,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,CAAC;IACpE,CAAC;IAEO,qBAAqB;QAC3B,OAAO,IAAI,CAAC,kBAA6B,CAAC;IAC5C,CAAC;IAEM,iBAAiB;QACtB,OAAO,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC;IAC1C,CAAC;IAEM,mBAAmB,CAAC,KAAU;QACnC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,GAAG,KAAK,CAAC;IACtD,CAAC;IAEM,uBAAuB,CAAC,KAAU;QACvC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,EAAE,CAAC;YACjD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,GAAG,EAAS,CAAC;QAC1D,CAAC;QACA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC;IAEM,mCAAmC,CAAC,UAAe;QACxD,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;gBACzC,UAAU,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC;YAC3C,CAAC;YACD,UAAU,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAEM,aAAa,CAAC,MAAc;QACjC,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,QAAQ,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,kBAAkB,OAC7F,IAAI,CAAC,cACP,IAAI,IAAI,CAAC,kBAAkB,KAAK,MAAM,EAAE,CAAC;IAC3C,CAAC;CACF;AA5DD,sDA4DC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DataSource, EntityTarget } from "typeorm";
|
|
2
|
+
export declare class Fixture {
|
|
3
|
+
private dataSource;
|
|
4
|
+
private repository;
|
|
5
|
+
private context;
|
|
6
|
+
private contextHistory;
|
|
7
|
+
private static globalCounter;
|
|
8
|
+
static IsLogEnabled: boolean;
|
|
9
|
+
constructor(dataSource: DataSource);
|
|
10
|
+
create<T>(type: EntityTarget<T>, providedValues?: Partial<T>): Promise<T>;
|
|
11
|
+
private createInternal;
|
|
12
|
+
private logInstanceCreated;
|
|
13
|
+
createMany<T>(times: number, type: EntityTarget<T>, providedValues?: Partial<T>): Promise<T[]>;
|
|
14
|
+
private allRequiredColumnsAreSet;
|
|
15
|
+
private handleScalarColumns;
|
|
16
|
+
private defaultForColumn;
|
|
17
|
+
private getMaxLengthForColumn;
|
|
18
|
+
private assignProvidedValuesToInstance;
|
|
19
|
+
private assignProvidedValueToInstance;
|
|
20
|
+
private handleOneToOne;
|
|
21
|
+
private handleManyToOne;
|
|
22
|
+
private handleManyToMany;
|
|
23
|
+
private handleOneToMany;
|
|
24
|
+
private addToContext;
|
|
25
|
+
private getFromContext;
|
|
26
|
+
private getIndex;
|
|
27
|
+
/**
|
|
28
|
+
* Resets the context, so previously created entities are no longer reused.
|
|
29
|
+
*/
|
|
30
|
+
resetContext(): void;
|
|
31
|
+
private resetContextHistory;
|
|
32
|
+
/**
|
|
33
|
+
* Resets the DataSource and the repository used by the Fixture.
|
|
34
|
+
* It's called by TestManager to reset the same instance of Fixture when the DataSource is changed.
|
|
35
|
+
* Other than that, this is only useful when you want to use a different DataSource (e.g., different database connection) in the same test suite.
|
|
36
|
+
*/
|
|
37
|
+
resetDataSource(dataSource: DataSource): void;
|
|
38
|
+
private log;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=fixture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../src/fixture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAiC,YAAY,EAAE,MAAM,SAAS,CAAC;AAGlF,qBAAa,OAAO;IAOC,OAAO,CAAC,UAAU;IANrC,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,MAAM,CAAC,aAAa,CAAK;IACjC,OAAc,YAAY,UAAS;gBAER,UAAU,EAAE,UAAU;IAIpC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,cAAc,GAAE,OAAO,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,CAAC,CAAC;YAQ5E,cAAc;IAoB5B,OAAO,CAAC,kBAAkB;IAMb,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,cAAc,GAAE,OAAO,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAQ/G,OAAO,CAAC,wBAAwB;IAehC,OAAO,CAAC,mBAAmB;IA+B3B,OAAO,CAAC,gBAAgB;IAwCxB,OAAO,CAAC,qBAAqB;IAQ7B,OAAO,CAAC,8BAA8B;IAStC,OAAO,CAAC,6BAA6B;YAMvB,cAAc;YA6Bd,eAAe;YAkCf,gBAAgB;YAuChB,eAAe;IAe7B,OAAO,CAAC,YAAY;IAcpB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,QAAQ;IAOhB;;OAEG;IACI,YAAY,IAAI,IAAI;IAK3B,OAAO,CAAC,mBAAmB;IAK3B;;;;OAIG;IACI,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAQpD,OAAO,CAAC,GAAG;CAMZ"}
|
package/dist/fixture.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Fixture = void 0;
|
|
13
|
+
const fixture_relation_helper_1 = require("./fixture-relation.helper");
|
|
14
|
+
class Fixture {
|
|
15
|
+
constructor(dataSource) {
|
|
16
|
+
this.dataSource = dataSource;
|
|
17
|
+
this.context = new Map();
|
|
18
|
+
this.contextHistory = new Map();
|
|
19
|
+
this.repository = this.dataSource.manager;
|
|
20
|
+
}
|
|
21
|
+
create(type_1) {
|
|
22
|
+
return __awaiter(this, arguments, void 0, function* (type, providedValues = {}) {
|
|
23
|
+
const name = this.dataSource.getMetadata(type).name;
|
|
24
|
+
this.log(`===> User Call: Create ${name} ===`);
|
|
25
|
+
const instance = yield this.createInternal(type, providedValues);
|
|
26
|
+
yield this.repository.save(instance);
|
|
27
|
+
return instance;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
createInternal(type_1) {
|
|
31
|
+
return __awaiter(this, arguments, void 0, function* (type, providedValues = {}) {
|
|
32
|
+
const meta = this.dataSource.getMetadata(type);
|
|
33
|
+
const instance = Object.create(meta.target.prototype);
|
|
34
|
+
this.log(`### Create ${meta.name} Started`);
|
|
35
|
+
this.handleScalarColumns(instance, meta, providedValues);
|
|
36
|
+
this.assignProvidedValuesToInstance(instance, meta, providedValues);
|
|
37
|
+
this.addToContext(instance, meta.name);
|
|
38
|
+
if (this.allRequiredColumnsAreSet(instance, meta)) {
|
|
39
|
+
yield this.repository.save(instance);
|
|
40
|
+
}
|
|
41
|
+
yield this.handleOneToOne(instance, meta, providedValues);
|
|
42
|
+
yield this.handleManyToOne(instance, meta, providedValues);
|
|
43
|
+
yield this.handleOneToMany(instance, meta, providedValues);
|
|
44
|
+
yield this.handleManyToMany(instance, meta, providedValues);
|
|
45
|
+
yield this.repository.save(instance);
|
|
46
|
+
this.logInstanceCreated(instance, meta);
|
|
47
|
+
return instance;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
logInstanceCreated(instance, meta) {
|
|
51
|
+
const primaryKeyColumnName = meta.primaryColumns[0].propertyName;
|
|
52
|
+
const primaryKeyValue = instance[primaryKeyColumnName];
|
|
53
|
+
this.log(`### Created ${meta.name}. PK: ${primaryKeyColumnName} = ${primaryKeyValue}`);
|
|
54
|
+
}
|
|
55
|
+
createMany(times_1, type_1) {
|
|
56
|
+
return __awaiter(this, arguments, void 0, function* (times, type, providedValues = {}) {
|
|
57
|
+
const results = [];
|
|
58
|
+
for (let i = 0; i < times; i++) {
|
|
59
|
+
results.push(yield this.create(type, providedValues));
|
|
60
|
+
}
|
|
61
|
+
return results;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
allRequiredColumnsAreSet(instance, meta) {
|
|
65
|
+
let foundRequiredWithNull = false;
|
|
66
|
+
for (const column of meta.columns) {
|
|
67
|
+
const name = column.propertyName;
|
|
68
|
+
if (column.generationStrategy === "increment" || column.isNullable) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (instance[name] === undefined || instance[name] === null) {
|
|
72
|
+
foundRequiredWithNull = true;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return !foundRequiredWithNull;
|
|
77
|
+
}
|
|
78
|
+
handleScalarColumns(instance, meta, providedValues) {
|
|
79
|
+
for (const column of meta.columns) {
|
|
80
|
+
const name = column.propertyName;
|
|
81
|
+
const provided = providedValues[name];
|
|
82
|
+
if (provided !== undefined) {
|
|
83
|
+
instance[name] = provided;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (column.generationStrategy === "increment") {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (column.isNullable ||
|
|
90
|
+
column.relationMetadata ||
|
|
91
|
+
column.isCreateDate ||
|
|
92
|
+
column.isUpdateDate ||
|
|
93
|
+
column.isVersion) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const isColumnUsedInRelation = meta.relations
|
|
97
|
+
.map((r) => r.joinColumns)
|
|
98
|
+
.map((jcs) => jcs.map((jc) => jc.propertyAliasName))
|
|
99
|
+
.flat();
|
|
100
|
+
if (isColumnUsedInRelation.includes(column.databaseName)) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
instance[name] = this.defaultForColumn(column, meta);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
defaultForColumn(column, meta) {
|
|
107
|
+
const columnType = column.type;
|
|
108
|
+
if (typeof columnType !== "string") {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
if (column.default !== undefined && typeof column.default !== "function") {
|
|
112
|
+
return column.default;
|
|
113
|
+
}
|
|
114
|
+
const s = columnType.toLowerCase();
|
|
115
|
+
if (["int", "integer", "bigint", "smallint", "decimal", "numeric", "float", "double", "real"].some((x) => s.includes(x))) {
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
118
|
+
if (["bool", "boolean"].some((x) => s.includes(x)))
|
|
119
|
+
return false;
|
|
120
|
+
if (["date", "time", "timestamp", "datetime"].some((x) => s.includes(x)))
|
|
121
|
+
return new Date(0);
|
|
122
|
+
if (["json", "jsonb"].some((x) => s.includes(x)))
|
|
123
|
+
return {};
|
|
124
|
+
if (["uuid"].some((x) => s.includes(x)))
|
|
125
|
+
return undefined;
|
|
126
|
+
if (columnType.includes("enum") && column.enum) {
|
|
127
|
+
return column.enum[0];
|
|
128
|
+
}
|
|
129
|
+
// Use global counter for guaranteed uniqueness across all test runs.
|
|
130
|
+
// The counter persists for the entire test suite run, including across database resets.
|
|
131
|
+
// Trim from the prefix to always preserve the suffix, which contains the uniqueness guarantee.
|
|
132
|
+
Fixture.globalCounter++;
|
|
133
|
+
const counterSuffix = `-${Fixture.globalCounter.toString(36)}`;
|
|
134
|
+
const max = this.getMaxLengthForColumn(column);
|
|
135
|
+
if (counterSuffix.length >= max) {
|
|
136
|
+
return counterSuffix.slice(-max);
|
|
137
|
+
}
|
|
138
|
+
const prefixBudget = max - counterSuffix.length;
|
|
139
|
+
const prefix = `${column.propertyName}${this.getIndex(meta.name)}`.substring(0, prefixBudget);
|
|
140
|
+
return `${prefix}${counterSuffix}`;
|
|
141
|
+
}
|
|
142
|
+
getMaxLengthForColumn(column) {
|
|
143
|
+
let max = 255;
|
|
144
|
+
if (column.length !== "" && column.length !== undefined && !isNaN(Number(column.length))) {
|
|
145
|
+
max = Number(column.length);
|
|
146
|
+
}
|
|
147
|
+
return max;
|
|
148
|
+
}
|
|
149
|
+
assignProvidedValuesToInstance(instance, meta, params) {
|
|
150
|
+
for (const column of meta.columns) {
|
|
151
|
+
this.assignProvidedValueToInstance(instance, column.propertyName, params[column.propertyName]);
|
|
152
|
+
}
|
|
153
|
+
for (const relation of meta.relations) {
|
|
154
|
+
this.assignProvidedValueToInstance(instance, relation.propertyName, params[relation.propertyName]);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
assignProvidedValueToInstance(instance, propertyName, provideValue) {
|
|
158
|
+
if (provideValue !== undefined) {
|
|
159
|
+
instance[propertyName] = provideValue;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
handleOneToOne(instance, meta, params) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
for (const relation of meta.relations.filter((r) => r.isOneToOne && !r.isOwning)) {
|
|
165
|
+
const helper = new fixture_relation_helper_1.FixtureRelationHelper(instance, relation, params);
|
|
166
|
+
if (helper.userProvidedValue()) {
|
|
167
|
+
helper.setInstanceProperty(helper.providedValue);
|
|
168
|
+
this.log(helper.getLogMessage("Use Provided"));
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (helper.isNullable) {
|
|
172
|
+
this.log(helper.getLogMessage("No Action Because Nullable"));
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (!this.dataSource.hasMetadata(helper.targetType)) {
|
|
176
|
+
this.log(helper.getLogMessage("No Action Because Other Type Not Found"));
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
this.log(`${helper.getLogMessage("-> Create")}`);
|
|
180
|
+
const created = yield this.createInternal(helper.targetType, {
|
|
181
|
+
[helper.targetPropertyName]: instance,
|
|
182
|
+
});
|
|
183
|
+
helper.setInstanceProperty(created);
|
|
184
|
+
this.log(helper.getLogMessage("Assigned"));
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
handleManyToOne(instance, meta, params) {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
for (const relation of meta.relations.filter((r) => r.isManyToOne)) {
|
|
191
|
+
const helper = new fixture_relation_helper_1.FixtureRelationHelper(instance, relation, params);
|
|
192
|
+
if (helper.userProvidedValue()) {
|
|
193
|
+
helper.setInstanceProperty(helper.providedValue);
|
|
194
|
+
this.log(helper.getLogMessage("Use Provided Value"));
|
|
195
|
+
helper.addThisInstanceToTheTargetSideArray(helper.providedValue);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (helper.isNullable) {
|
|
199
|
+
this.log(helper.getLogMessage("No Action Because Nullable"));
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const reuse = this.getFromContext(helper.targetTypeName);
|
|
203
|
+
if (reuse) {
|
|
204
|
+
helper.setInstanceProperty(reuse);
|
|
205
|
+
this.log(helper.getLogMessage("Use Cached"));
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (this.dataSource.hasMetadata(helper.targetType)) {
|
|
209
|
+
const createDependencyReferencingMe = {
|
|
210
|
+
[helper.targetPropertyName]: [instance],
|
|
211
|
+
};
|
|
212
|
+
this.log(helper.getLogMessage("Create " + helper.targetTypeName));
|
|
213
|
+
const created = yield this.createInternal(helper.targetType, createDependencyReferencingMe);
|
|
214
|
+
helper.setInstanceProperty(created);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
handleManyToMany(instance, meta, providedValues) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
var _a;
|
|
222
|
+
for (const relation of meta.relations.filter((r) => r.isManyToMany)) {
|
|
223
|
+
const helper = new fixture_relation_helper_1.FixtureRelationHelper(instance, relation, providedValues);
|
|
224
|
+
if (helper.userProvidedValue()) {
|
|
225
|
+
helper.setInstanceProperty(helper.providedValue);
|
|
226
|
+
this.log(helper.getLogMessage("Use Provided Value"));
|
|
227
|
+
for (const p of helper.providedValue) {
|
|
228
|
+
if (!p[helper.targetPropertyName]) {
|
|
229
|
+
p[helper.targetPropertyName] = [];
|
|
230
|
+
}
|
|
231
|
+
if (relation.isOwning) {
|
|
232
|
+
if (!p[helper.targetPropertyName].includes(instance)) {
|
|
233
|
+
p[helper.targetPropertyName].push(instance);
|
|
234
|
+
yield this.repository.save(p);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
helper.addThisInstanceToTheTargetSideArray(helper.providedValue);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const reuse = this.getFromContext(helper.targetTypeName);
|
|
242
|
+
if (reuse) {
|
|
243
|
+
this.log(helper.getLogMessage("Use Cached"));
|
|
244
|
+
if ((_a = instance[helper.sourcePropertyName]) === null || _a === void 0 ? void 0 : _a.includes(reuse)) {
|
|
245
|
+
//I'm already part of the list
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
helper.addThisInstanceToTheTargetSideArray(reuse);
|
|
249
|
+
yield this.repository.save(reuse);
|
|
250
|
+
helper.addValueToInstanceArray(reuse);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
this.log(helper.getLogMessage("No Action"));
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
handleOneToMany(instance, meta, params) {
|
|
258
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
for (const relation of meta.relations.filter((r) => r.isOneToMany)) {
|
|
260
|
+
const helper = new fixture_relation_helper_1.FixtureRelationHelper(instance, relation, params);
|
|
261
|
+
if (helper.userProvidedValue()) {
|
|
262
|
+
this.log(helper.getLogMessage("Use Provided"));
|
|
263
|
+
helper.setInstanceProperty(helper.providedValue);
|
|
264
|
+
yield this.repository.save(instance);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
this.log(helper.getLogMessage("No Action"));
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
addToContext(instance, name) {
|
|
272
|
+
if (!this.context.has(name)) {
|
|
273
|
+
this.context.set(name, []);
|
|
274
|
+
}
|
|
275
|
+
this.context.get(name).push(instance);
|
|
276
|
+
//indexes
|
|
277
|
+
if (!this.contextHistory.has(name)) {
|
|
278
|
+
this.contextHistory.set(name, 1);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
this.contextHistory.set(name, this.contextHistory.get(name) + 1);
|
|
282
|
+
}
|
|
283
|
+
getFromContext(name) {
|
|
284
|
+
if (!this.context.has(name)) {
|
|
285
|
+
this.context.set(name, []);
|
|
286
|
+
}
|
|
287
|
+
const items = this.context.get(name);
|
|
288
|
+
return items[items.length - 1];
|
|
289
|
+
}
|
|
290
|
+
getIndex(name) {
|
|
291
|
+
if (!this.contextHistory.has(name)) {
|
|
292
|
+
this.contextHistory.set(name, 1);
|
|
293
|
+
}
|
|
294
|
+
return this.contextHistory.get(name);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Resets the context, so previously created entities are no longer reused.
|
|
298
|
+
*/
|
|
299
|
+
resetContext() {
|
|
300
|
+
this.context = new Map();
|
|
301
|
+
this.log("=== Context Reset ===");
|
|
302
|
+
}
|
|
303
|
+
resetContextHistory() {
|
|
304
|
+
this.contextHistory = new Map();
|
|
305
|
+
this.log("=== Context History Reset ===");
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Resets the DataSource and the repository used by the Fixture.
|
|
309
|
+
* It's called by TestManager to reset the same instance of Fixture when the DataSource is changed.
|
|
310
|
+
* Other than that, this is only useful when you want to use a different DataSource (e.g., different database connection) in the same test suite.
|
|
311
|
+
*/
|
|
312
|
+
resetDataSource(dataSource) {
|
|
313
|
+
this.dataSource = dataSource;
|
|
314
|
+
this.repository = this.dataSource.manager;
|
|
315
|
+
this.resetContext();
|
|
316
|
+
this.resetContextHistory();
|
|
317
|
+
this.log("=== DataSource Reset ===");
|
|
318
|
+
}
|
|
319
|
+
log(message) {
|
|
320
|
+
if (!Fixture.IsLogEnabled) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
console.log(message);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
exports.Fixture = Fixture;
|
|
327
|
+
Fixture.globalCounter = 0;
|
|
328
|
+
Fixture.IsLogEnabled = false;
|
|
329
|
+
//# sourceMappingURL=fixture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture.js","sourceRoot":"","sources":["../src/fixture.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,uEAAkE;AAElE,MAAa,OAAO;IAOlB,YAA2B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QALzC,YAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;QACnC,mBAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;QAKjD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;IAC5C,CAAC;IAEY,MAAM;6DAAI,IAAqB,EAAE,iBAA6B,EAAE;YAC3E,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;YACpD,IAAI,CAAC,GAAG,CAAC,0BAA0B,IAAI,MAAM,CAAC,CAAC;YAC/C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE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IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;YAC1B,OAAO;QACT,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;;AAnVH,0BAoVC;AAhVgB,qBAAa,GAAG,CAAC,AAAJ,CAAK;AACnB,oBAAY,GAAG,KAAK,AAAR,CAAS"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Fixture = void 0;
|
|
4
|
+
var fixture_1 = require("./fixture");
|
|
5
|
+
Object.defineProperty(exports, "Fixture", { enumerable: true, get: function () { return fixture_1.Fixture; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAA3B,kGAAA,OAAO,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valid-values.d.ts","sourceRoot":"","sources":["../src/valid-values.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valid-values.js","sourceRoot":"","sources":["../src/valid-values.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "typeorm-autofixtures",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Automatic fixtures for typeorm",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc -p tsconfig.build.json",
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
13
|
+
"test": "jest"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"typeorm",
|
|
17
|
+
"fixtures",
|
|
18
|
+
"testing",
|
|
19
|
+
"test-data",
|
|
20
|
+
"auto-fixtures"
|
|
21
|
+
],
|
|
22
|
+
"author": "andrecarlucci",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/andrecarlucci/typeorm-fixtures.git"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"typeorm": ">=0.3.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/jest": "^30.0.0",
|
|
33
|
+
"jest": "^30.2.0",
|
|
34
|
+
"pg": "^8.17.1",
|
|
35
|
+
"pg-mem": "^3.0.5",
|
|
36
|
+
"ts-jest": "^29.4.6",
|
|
37
|
+
"typeorm": "^0.3.28",
|
|
38
|
+
"typescript": "^5.9.3"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Fixtures
|
|
2
|
+
|
|
3
|
+
You can use Fixture to speed up creating the database entities you need for your tests.
|
|
4
|
+
|
|
5
|
+
The fixture object will automatically create and keep track of every entity required to construct the target one. It has an internal context to and reuses the last created entity of a given type every time it is required to create a new object.
|
|
6
|
+
|
|
7
|
+
## Rules to have in mind
|
|
8
|
+
|
|
9
|
+
- it only creates non-nullable properties and relations
|
|
10
|
+
- for relations
|
|
11
|
+
- One-to-One: create only if not owner
|
|
12
|
+
- Many-to-One: always create
|
|
13
|
+
- One-to-Many: never create
|
|
14
|
+
- Many-to-Many: never create
|
|
15
|
+
|
|
16
|
+
\*Owner: side of the relation with join column (Many-to-Many or One-to-One)
|
|
17
|
+
|
|
18
|
+
## Simple use
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
await database.refreshDatabase();
|
|
23
|
+
repository = (await database.getDataSource()).createEntityManager();
|
|
24
|
+
fixture = new Fixture(await database.getDataSource());
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('Creates a Task', async () => {
|
|
28
|
+
const task = await fixture.create(Task);
|
|
29
|
+
expect(task.id).toBeDefined();
|
|
30
|
+
expect(task.project).toBeDefined();
|
|
31
|
+
expect(task.users).toBeUndefined();
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Fixture will:
|
|
36
|
+
|
|
37
|
+
1. Create the object Task and stub all of its non-nullable properties.
|
|
38
|
+
2. Loop through all its properties and relations:
|
|
39
|
+
1. Find MANY-TO-ONE for Task.project -> Project.tasks: Create a Project
|
|
40
|
+
2. Loop through all Project properties and relations:
|
|
41
|
+
1. Find ONE-TO-MANY for Project.tasks -> Task.project: No Action (one-to-many)
|
|
42
|
+
3. Find MANY-TO-MANY for Task.users -> User.tasks: No Action (many-to-many)
|
|
43
|
+
3. Returns the Task object populated.
|
|
44
|
+
|
|
45
|
+
## Using the context
|
|
46
|
+
|
|
47
|
+
Every time an object is created, it stays in the context.
|
|
48
|
+
So, calling methods like this:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
const task1 = await fixture.create(Task);
|
|
52
|
+
const task2 = await fixture.create(Task);
|
|
53
|
+
expect(task1.project).toBe(task2.project);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Will automatically reuse the previously created Project for both Tasks.
|
|
57
|
+
|
|
58
|
+
If you don't want this behaviour, just call `fixture.resetContext()` and your next calls will be in a completely different object graph.
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
const task1 = await fixture.create(Task);
|
|
62
|
+
fixture.resetContext();
|
|
63
|
+
const task2 = await fixture.create(Task);
|
|
64
|
+
expect(task1.project).not.toBe(task2.project);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Provide your own values
|
|
68
|
+
|
|
69
|
+
Every `fixture.create(Type)` accepts a `Partial<Type>` as a parameter where you can specify your own values for the creation of the object.
|
|
70
|
+
|
|
71
|
+
Ex:
|
|
72
|
+
Scalar types:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
const project = await fixture.create(Project, { name: 'My Project' });
|
|
76
|
+
expect(project.name).toBe('My Project');
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Or objects:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
const project = await fixture.create(Project);
|
|
83
|
+
const task = await fixture.create(Task, { project });
|
|
84
|
+
expect(task.project).toBe(project);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
You can find many more examples in the [fixture's test](./test/fixture.test.ts) file.
|