-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.spec.ts
32 lines (26 loc) · 1.01 KB
/
product.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import Product from './product'
import { Spec } from '../src'
import { expect, test, describe } from "bun:test"
describe('제품 스펙 테스트', () => {
const products = [
new Product(100, "widgetA"),
new Product(1100, "widgetB"),
new Product(2000, "widgetA"),
new Product(300, "widgetB"),
]
test('제품에 A란 명칭이 포함되지 않은 상품 또는 가경이 1000원이상인 상품', () => {
// 제품명에 pattern이 포함되어야한다.
const nameContains = (pattern: string) => (product: Product) => product.name.includes(pattern)
// 제품이 해당 가격보다 높아야한다.
const highPrice = new Spec(
(product: Product) => product.price >= 1000
);
const spec = new Spec(nameContains(`A`)).not().or(highPrice);
const product = products.filter(x => spec.safe(x)).map(Product.info);
expect(product).toEqual([
{ name: 'widgetB', price: 1100 },
{ name: 'widgetA', price: 2000 },
{ name: 'widgetB', price: 300 }
]);
})
})