Skip to content

Commit a965240

Browse files
committed
Added currentForType scope test
1 parent c88f781 commit a965240

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

tests/Feature/ScopesTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,67 @@
3636
$this->assertNotNull($price->activated_at);
3737
});
3838

39+
test('the currentForType scope can return the correct price', function() {
40+
$priceable_item = new PriceableItem(['id' => 1234]);
41+
42+
$priceable_item->setPrice(
43+
type: 'selling',
44+
amount: 123,
45+
currency: 'EUR',
46+
activated_at: now()->subWeeks(2)
47+
);
48+
49+
$priceable_item->setPrice(
50+
type: 'selling',
51+
amount: 456,
52+
currency: 'EUR',
53+
activated_at: now()->subWeek()
54+
);
55+
56+
$priceable_item->setPrice(
57+
type: 'selling',
58+
amount: 789,
59+
currency: 'EUR',
60+
activated_at: now()->addWeek()
61+
);
62+
63+
$priceable_item->setPrice(
64+
type: 'buying',
65+
amount: 111,
66+
currency: 'EUR',
67+
activated_at: now()->subWeeks(2)
68+
);
69+
70+
$priceable_item->setPrice(
71+
type: 'buying',
72+
amount: 222,
73+
currency: 'EUR',
74+
activated_at: now()->subWeek()
75+
);
76+
77+
$priceable_item->setPrice(
78+
type: 'buying',
79+
amount: 333,
80+
currency: 'EUR',
81+
activated_at: now()->addWeek()
82+
);
83+
84+
$sellingPrice = $priceable_item->prices()->currentForType('selling')->first();
85+
$buyingPrice = $priceable_item->prices()->currentForType('buying')->first();
86+
87+
$this->assertNotNull($sellingPrice);
88+
$this->assertInstanceOf(Price::class, $sellingPrice);
89+
$this->assertSame((string) $priceable_item->id, $sellingPrice->priceable_id);
90+
$this->assertSame(45600, $sellingPrice->amount);
91+
$this->assertNotNull($sellingPrice->activated_at);
92+
93+
$this->assertNotNull($buyingPrice);
94+
$this->assertInstanceOf(Price::class, $buyingPrice);
95+
$this->assertSame((string) $priceable_item->id, $buyingPrice->priceable_id);
96+
$this->assertSame(22200, $buyingPrice->amount);
97+
$this->assertNotNull($buyingPrice->activated_at);
98+
});
99+
39100
test('the effectiveAt scope can return the correct price', function() {
40101
$priceable_item = new PriceableItem(['id' => 1234]);
41102

0 commit comments

Comments
 (0)