|
36 | 36 | $this->assertNotNull($price->activated_at);
|
37 | 37 | });
|
38 | 38 |
|
| 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 | + |
39 | 100 | test('the effectiveAt scope can return the correct price', function() {
|
40 | 101 | $priceable_item = new PriceableItem(['id' => 1234]);
|
41 | 102 |
|
|
0 commit comments