Skip to content

Commit c6c121f

Browse files
committed
feat: testing product factory
1 parent d12b0dd commit c6c121f

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

src/app/testing/product-factory.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import {
2+
CMRProduct,
3+
CMRProductMetadata,
4+
Dataset,
5+
FlightDirection,
6+
} from '@models';
7+
import moment from 'moment';
8+
9+
function createProduct(product: CMRProduct): CMRProduct {
10+
return product;
11+
}
12+
13+
class ProductFactory {
14+
withBasicInfo(name: string): NestedProductFactory {
15+
return new NestedProductFactory(
16+
createProduct({
17+
name: name,
18+
productTypeDisplay: '',
19+
file: '',
20+
id: '',
21+
downloadUrl: '',
22+
bytes: 100 * 1000000,
23+
dataset: 'SENTINEL-1',
24+
browses: [],
25+
thumbnail: '',
26+
groupId: '',
27+
isUnzippedFile: false,
28+
isDummyProduct: false,
29+
metadata: {
30+
date: moment(),
31+
stopDate: moment().add(2),
32+
polygon: '',
33+
34+
productType: '',
35+
beamMode: '',
36+
polarization: '',
37+
flightDirection: FlightDirection.ASCENDING,
38+
39+
path: 0,
40+
frame: 0,
41+
absoluteOrbit: [],
42+
43+
collectionName: '',
44+
collectionID: '',
45+
46+
stackSize: 0,
47+
faradayRotation: 0,
48+
offNadirAngle: 0,
49+
instrument: '',
50+
pointingAngle: '',
51+
missionName: '',
52+
flightLine: '',
53+
perpendicular: 0,
54+
temporal: 0,
55+
canInSAR: false,
56+
burst: undefined,
57+
opera: undefined,
58+
nisar: undefined,
59+
fileName: '',
60+
job: undefined,
61+
pgeVersion: '',
62+
subproducts: [],
63+
parentID: '',
64+
ariaVersion: '',
65+
},
66+
}),
67+
);
68+
}
69+
}
70+
71+
class NestedProductFactory {
72+
constructor(private _product: Readonly<CMRProduct>) {}
73+
74+
build() {
75+
return this._product;
76+
}
77+
78+
withAOI(): NestedProductFactory {
79+
return this._extendWithMetadata({
80+
polygon:
81+
'POLYGON((-124.3885 36.7031,-120.6971 36.7031,-120.6971 38.9246,-124.3885 38.9246,-124.3885 36.7031))',
82+
});
83+
}
84+
withDataset(productDataset: Dataset) {
85+
return this._extendWith({
86+
dataset: productDataset.id,
87+
});
88+
}
89+
90+
private _extendWith(product: Partial<CMRProduct>) {
91+
return new NestedProductFactory({ ...this._product, ...product });
92+
}
93+
private _extendWithMetadata(productMetadata: Partial<CMRProductMetadata>) {
94+
return new NestedProductFactory({
95+
...this._product,
96+
metadata: {
97+
...this._product.metadata,
98+
...productMetadata,
99+
},
100+
});
101+
}
102+
}
103+
104+
export const productFactory = new ProductFactory();

0 commit comments

Comments
 (0)