Skip to content

Commit b46d89d

Browse files
committed
feat: product factory test with service
1 parent c6c121f commit b46d89d

2 files changed

Lines changed: 118 additions & 10 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import * as models from '@models';
4+
import { productFactory } from '@testing/product-factory';
5+
import { beforeEach, describe, expect, it } from 'vitest';
6+
7+
import { DatasetForProductService } from './dataset-for-product.service';
8+
9+
describe('DatasetForProductService', () => {
10+
let service: DatasetForProductService;
11+
12+
beforeEach(() => {
13+
TestBed.configureTestingModule({});
14+
service = TestBed.inject(DatasetForProductService);
15+
});
16+
17+
describe('match()', () => {
18+
it('returns alos for ALOS dataset without AVNIR-2 instrument', () => {
19+
const product = productFactory
20+
.withBasicInfo('test-scene')
21+
.withDataset('ALOS')
22+
.build();
23+
expect(service.match(product)).toBe(models.alos);
24+
});
25+
26+
it('returns avnir for ALOS dataset with AVNIR-2 instrument', () => {
27+
const product = productFactory
28+
.withBasicInfo('test-scene')
29+
.withDataset('ALOS')
30+
.withInstrument('AVNIR-2')
31+
.build();
32+
expect(service.match(product)).toBe(models.avnir);
33+
});
34+
35+
it('returns sentinel_1_bursts for BURST product type', () => {
36+
const product = productFactory
37+
.withBasicInfo('test-scene')
38+
.withProductType('BURST')
39+
.build();
40+
expect(service.match(product)).toBe(models.sentinel_1_bursts);
41+
});
42+
43+
it('returns tropo for TROPO-ZENITH product type', () => {
44+
const product = productFactory
45+
.withBasicInfo('test-scene')
46+
.withProductType('TROPO-ZENITH')
47+
.build();
48+
expect(service.match(product)).toBe(models.tropo);
49+
});
50+
51+
it('returns tropo for ECMWF_TROPO product type', () => {
52+
const product = productFactory
53+
.withBasicInfo('test-scene')
54+
.withProductType('ECMWF_TROPO')
55+
.build();
56+
expect(service.match(product)).toBe(models.tropo);
57+
});
58+
59+
it('returns opera_s1 for OPERA product id', () => {
60+
const product = productFactory
61+
.withBasicInfo('test-scene')
62+
.withId('OPERA_L2_RTC-S1_T001')
63+
.build();
64+
expect(service.match(product)).toBe(models.opera_s1);
65+
});
66+
67+
it('returns SENTINEL-1 INTERFEROGRAM (BETA) for S1-GUNW name', () => {
68+
const product = productFactory
69+
.withBasicInfo('test-scene')
70+
.withName('S1-GUNW-D-N-123456-123456-HH-R-N-0001')
71+
.build();
72+
expect(service.match(product)).toBe(
73+
models.datasets['SENTINEL-1 INTERFEROGRAM (BETA)'],
74+
);
75+
});
76+
77+
it('returns sentinel-1 dataset for exact SENTINEL-1 dataset match', () => {
78+
const product = productFactory.withBasicInfo('test-scene').build();
79+
expect(service.match(product)).toBe(models.datasets['SENTINEL-1']);
80+
});
81+
82+
it('returns sentinel-1 dataset for Sentinel-1A via partial match', () => {
83+
const product = productFactory
84+
.withBasicInfo('test-scene')
85+
.withDataset('Sentinel-1A')
86+
.build();
87+
expect(service.match(product)).toBe(models.datasets['SENTINEL-1']);
88+
});
89+
// TODO: Change this to default to SENTINEL-1 again?
90+
it('returns NISAR for non matching dataset', () => {
91+
const product = productFactory
92+
.withBasicInfo('test-scene')
93+
.withDataset('')
94+
.build();
95+
expect(service.match(product)).toBe(models.datasets.NISAR);
96+
});
97+
});
98+
});

src/app/testing/product-factory.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
CMRProduct,
3-
CMRProductMetadata,
4-
Dataset,
5-
FlightDirection,
6-
} from '@models';
1+
import { CMRProduct, CMRProductMetadata, FlightDirection } from '@models';
72
import moment from 'moment';
83

94
function createProduct(product: CMRProduct): CMRProduct {
@@ -81,10 +76,25 @@ class NestedProductFactory {
8176
'POLYGON((-124.3885 36.7031,-120.6971 36.7031,-120.6971 38.9246,-124.3885 38.9246,-124.3885 36.7031))',
8277
});
8378
}
84-
withDataset(productDataset: Dataset) {
85-
return this._extendWith({
86-
dataset: productDataset.id,
87-
});
79+
80+
withDataset(dataset: string): NestedProductFactory {
81+
return this._extendWith({ dataset });
82+
}
83+
84+
withInstrument(instrument: string): NestedProductFactory {
85+
return this._extendWithMetadata({ instrument });
86+
}
87+
88+
withProductType(productType: string): NestedProductFactory {
89+
return this._extendWithMetadata({ productType });
90+
}
91+
92+
withId(id: string): NestedProductFactory {
93+
return this._extendWith({ id });
94+
}
95+
96+
withName(name: string): NestedProductFactory {
97+
return this._extendWith({ name });
8898
}
8999

90100
private _extendWith(product: Partial<CMRProduct>) {

0 commit comments

Comments
 (0)