CoreTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. <?php
  2. use Webkul\Core\Enums\CurrencyPositionEnum;
  3. use Webkul\Core\Models\Channel;
  4. use Webkul\Core\Models\Currency;
  5. it('returns all channels', function () {
  6. // Arrange
  7. $expectedChannel = Channel::factory()->create();
  8. // Act
  9. $channels = core()->getAllChannels();
  10. // Assert
  11. expect($channels->count())->toBe(2);
  12. expect($channels->where('id', $expectedChannel->id))->toBeTruthy();
  13. });
  14. it('returns the current channel', function () {
  15. // Arrange
  16. $expectedChannel = Channel::factory()->create();
  17. // Act
  18. $channel = core()->getCurrentChannel($expectedChannel->hostname);
  19. // Assert
  20. expect($channel->id)->toBe($expectedChannel->id);
  21. expect($channel->code)->toBe($expectedChannel->code);
  22. });
  23. it('returns the current channel when set via setter', function () {
  24. // Arrange
  25. $expectedChannel = Channel::factory()->create();
  26. // Act
  27. core()->setCurrentChannel($expectedChannel);
  28. $channel = core()->getCurrentChannel();
  29. // Assert
  30. expect($channel->id)->toBe($expectedChannel->id);
  31. expect($channel->code)->toBe($expectedChannel->code);
  32. });
  33. it('returns the current channel code', function () {
  34. // Arrange
  35. $expectedChannel = Channel::factory()->create();
  36. // Act
  37. core()->setCurrentChannel($expectedChannel);
  38. $channelCode = core()->getCurrentChannelCode();
  39. // Assert
  40. expect($channelCode)->toBe($expectedChannel->code);
  41. });
  42. it('returns the default channel', function () {
  43. // Arrange
  44. $expectedChannel = Channel::factory()->create();
  45. config()->set('app.channel', $expectedChannel->code);
  46. // Act
  47. $channel = core()->getDefaultChannel();
  48. // Assert
  49. expect($channel->id)->toBe($expectedChannel->id);
  50. expect($channel->code)->toBe($expectedChannel->code);
  51. });
  52. it('returns the first channel if the default channel is not found', function () {
  53. // Arrange
  54. $expectedChannel = Channel::first();
  55. config()->set('app.channel', 'wrong_channel_code');
  56. // Act
  57. $channel = core()->getDefaultChannel();
  58. // Assert
  59. expect($channel->id)->toBe($expectedChannel->id);
  60. expect($channel->code)->toBe($expectedChannel->code);
  61. });
  62. it('returns the default channel when set via setter', function () {
  63. // Arrange
  64. $expectedChannel = Channel::factory()->create();
  65. // Act
  66. core()->setDefaultChannel($expectedChannel);
  67. $channel = core()->getDefaultChannel();
  68. // Assert
  69. expect($channel->id)->toBe($expectedChannel->id);
  70. expect($channel->code)->toBe($expectedChannel->code);
  71. });
  72. it('returns the default channel code', function () {
  73. // Arrange
  74. $expectedChannel = Channel::factory()->create();
  75. // Act
  76. core()->setDefaultChannel($expectedChannel);
  77. $channelCode = core()->getDefaultChannelCode();
  78. // Assert
  79. expect($channelCode)->toBe($expectedChannel->code);
  80. });
  81. it('returns the requested channel', function () {
  82. // Arrange
  83. $expectedChannel = Channel::factory()->create();
  84. request()->merge([
  85. 'channel' => $expectedChannel->code,
  86. ]);
  87. // Act
  88. $channel = core()->getRequestedChannel();
  89. // Assert
  90. expect($channel->id)->toBe($expectedChannel->id);
  91. expect($channel->code)->toBe($expectedChannel->code);
  92. });
  93. it('returns the current channel if the requested channel code is not provided', function () {
  94. // Arrange
  95. $expectedChannel = Channel::factory()->create();
  96. core()->setCurrentChannel($expectedChannel);
  97. // Act
  98. $channel = core()->getRequestedChannel();
  99. // Assert
  100. expect($channel->id)->toBe($expectedChannel->id);
  101. expect($channel->code)->toBe($expectedChannel->code);
  102. });
  103. it('returns the requested channel code', function () {
  104. // Arrange
  105. $expectedChannel = Channel::factory()->create();
  106. request()->merge([
  107. 'channel' => $expectedChannel->code,
  108. ]);
  109. // Act
  110. $channelCode = core()->getRequestedChannelCode();
  111. // Assert
  112. expect($channelCode)->toBe($expectedChannel->code);
  113. });
  114. it('returns the current channel code if requested channel code is not provided', function () {
  115. // Arrange
  116. $expectedChannel = Channel::factory()->create();
  117. core()->setCurrentChannel($expectedChannel);
  118. // Act
  119. $channelCode = core()->getRequestedChannelCode();
  120. // Assert
  121. expect($channelCode)->toBe($expectedChannel->code);
  122. });
  123. it('should format the price with default symbol based on the current currency and use default formatter if currency position is not defined', function () {
  124. // Arrange
  125. $expectedSymbol = '$';
  126. $channel = Channel::factory()->create();
  127. $channel->base_currency->update([
  128. 'symbol' => null,
  129. 'currency_position' => null,
  130. ]);
  131. $price = number_format(fake()->randomFloat(min: 1, max: 500), $channel->base_currency->decimal);
  132. core()->setCurrentChannel($channel);
  133. // Act
  134. $formattedPrice = core()->formatPrice($price);
  135. // Assert
  136. expect($formattedPrice)->toBe($expectedSymbol.$price);
  137. });
  138. it('should format the price with custom symbol based on the current currency and use default formatter if currency position is not defined', function () {
  139. // Arrange
  140. $expectedSymbol = '€';
  141. $channel = Channel::factory()->create();
  142. $channel->base_currency->update([
  143. 'symbol' => $expectedSymbol,
  144. 'currency_position' => null,
  145. ]);
  146. $price = number_format(fake()->randomFloat(min: 1, max: 500), $channel->base_currency->decimal);
  147. core()->setCurrentChannel($channel);
  148. // Act
  149. $formattedPrice = core()->formatPrice($price);
  150. // Assert
  151. expect($formattedPrice)->toBe($expectedSymbol.$price);
  152. });
  153. it('should format the price based on the current currency and place the symbol on the left side', function () {
  154. // Arrange
  155. $channel = Channel::factory()->create();
  156. $channel->base_currency->update([
  157. 'currency_position' => CurrencyPositionEnum::LEFT->value,
  158. ]);
  159. $price = number_format(fake()->randomFloat(min: 1, max: 500), $channel->base_currency->decimal);
  160. core()->setCurrentChannel($channel);
  161. // Act
  162. $formattedPrice = core()->formatPrice($price);
  163. // Assert
  164. expect($formattedPrice)->toBe($channel->base_currency->symbol.$price);
  165. });
  166. it('should format the price based on the current currency and place the symbol on the left side with space', function () {
  167. // Arrange
  168. $channel = Channel::factory()->create();
  169. $channel->base_currency->update([
  170. 'currency_position' => CurrencyPositionEnum::LEFT_WITH_SPACE->value,
  171. ]);
  172. $price = number_format(fake()->randomFloat(min: 1, max: 500), $channel->base_currency->decimal);
  173. core()->setCurrentChannel($channel);
  174. // Act
  175. $formattedPrice = core()->formatPrice($price);
  176. // Assert
  177. expect($formattedPrice)->toBe($channel->base_currency->symbol.' '.$price);
  178. });
  179. it('should format the price based on the current currency and place the symbol on the right side', function () {
  180. // Arrange
  181. $channel = Channel::factory()->create();
  182. $channel->base_currency->update([
  183. 'currency_position' => CurrencyPositionEnum::RIGHT->value,
  184. ]);
  185. $price = number_format(fake()->randomFloat(min: 1, max: 500), $channel->base_currency->decimal);
  186. core()->setCurrentChannel($channel);
  187. // Act
  188. $formattedPrice = core()->formatPrice($price);
  189. // Assert
  190. expect($formattedPrice)->toBe($price.$channel->base_currency->symbol);
  191. });
  192. it('should format the price based on the current currency and place the symbol on the right side with space', function () {
  193. // Arrange
  194. $channel = Channel::factory()->create();
  195. $channel->base_currency->update([
  196. 'currency_position' => CurrencyPositionEnum::RIGHT_WITH_SPACE->value,
  197. ]);
  198. $price = number_format(fake()->randomFloat(min: 1, max: 500), $channel->base_currency->decimal);
  199. core()->setCurrentChannel($channel);
  200. // Act
  201. $formattedPrice = core()->formatPrice($price);
  202. // Assert
  203. expect($formattedPrice)->toBe($price.' '.$channel->base_currency->symbol);
  204. });
  205. it('should format the price based on the current currency and place the code on the left side if the symbol is not present', function () {
  206. // Arrange
  207. $channel = Channel::factory()->create();
  208. $channel->base_currency->update([
  209. 'symbol' => '',
  210. 'currency_position' => CurrencyPositionEnum::LEFT->value,
  211. ]);
  212. $price = number_format(fake()->randomFloat(min: 1, max: 500), $channel->base_currency->decimal);
  213. core()->setCurrentChannel($channel);
  214. // Act
  215. $formattedPrice = core()->formatPrice($price);
  216. // Assert
  217. expect($formattedPrice)->toBe($channel->base_currency->code.$price);
  218. });
  219. it('should format the price based on the current currency and place the code on the left side with space if the symbol is not present', function () {
  220. // Arrange
  221. $channel = Channel::factory()->create();
  222. $channel->base_currency->update([
  223. 'symbol' => '',
  224. 'currency_position' => CurrencyPositionEnum::LEFT_WITH_SPACE->value,
  225. ]);
  226. $price = number_format(fake()->randomFloat(min: 1, max: 500), $channel->base_currency->decimal);
  227. core()->setCurrentChannel($channel);
  228. // Act
  229. $formattedPrice = core()->formatPrice($price);
  230. // Assert
  231. expect($formattedPrice)->toBe($channel->base_currency->code.' '.$price);
  232. });
  233. it('should format the price based on the current currency and place the code on the right side if the symbol is not present', function () {
  234. // Arrange
  235. $channel = Channel::factory()->create();
  236. $channel->base_currency->update([
  237. 'symbol' => '',
  238. 'currency_position' => CurrencyPositionEnum::RIGHT->value,
  239. ]);
  240. $price = number_format(fake()->randomFloat(min: 1, max: 500), $channel->base_currency->decimal);
  241. core()->setCurrentChannel($channel);
  242. // Act
  243. $formattedPrice = core()->formatPrice($price);
  244. // Assert
  245. expect($formattedPrice)->toBe($price.$channel->base_currency->code);
  246. });
  247. it('should format the price based on the current currency and place the code on the right side with space if the symbol is not present', function () {
  248. // Arrange
  249. $channel = Channel::factory()->create();
  250. $channel->base_currency->update([
  251. 'symbol' => '',
  252. 'currency_position' => CurrencyPositionEnum::RIGHT_WITH_SPACE->value,
  253. ]);
  254. $price = number_format(fake()->randomFloat(min: 1, max: 500), $channel->base_currency->decimal);
  255. core()->setCurrentChannel($channel);
  256. // Act
  257. $formattedPrice = core()->formatPrice($price);
  258. // Assert
  259. expect($formattedPrice)->toBe($price.' '.$channel->base_currency->code);
  260. });
  261. it('should format the price based on the mentioned currency and place the symbol on the left side', function () {
  262. // Arrange
  263. $indianCurrency = Currency::factory()->create([
  264. 'code' => 'INR',
  265. 'name' => 'Indian Rupee',
  266. 'symbol' => '₹',
  267. 'currency_position' => CurrencyPositionEnum::LEFT->value,
  268. ]);
  269. $channel = Channel::factory()->create();
  270. $channel->currencies()->sync(Currency::all()->pluck('id')->toArray());
  271. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  272. core()->setCurrentChannel($channel);
  273. // Act
  274. $formattedPrice = core()->formatPrice($price, $indianCurrency->code);
  275. // Assert
  276. expect($formattedPrice)->toBe($indianCurrency->symbol.$price);
  277. });
  278. it('should format the price based on the mentioned currency and place the symbol on the left side with space', function () {
  279. // Arrange
  280. $indianCurrency = Currency::factory()->create([
  281. 'code' => 'INR',
  282. 'name' => 'Indian Rupee',
  283. 'symbol' => '₹',
  284. 'currency_position' => CurrencyPositionEnum::LEFT_WITH_SPACE->value,
  285. ]);
  286. $channel = Channel::factory()->create();
  287. $channel->currencies()->sync(Currency::all()->pluck('id')->toArray());
  288. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  289. core()->setCurrentChannel($channel);
  290. // Act
  291. $formattedPrice = core()->formatPrice($price, $indianCurrency->code);
  292. // Assert
  293. expect($formattedPrice)->toBe($indianCurrency->symbol.' '.$price);
  294. });
  295. it('should format the price based on the mentioned currency and place the symbol on the right side', function () {
  296. // Arrange
  297. $indianCurrency = Currency::factory()->create([
  298. 'code' => 'INR',
  299. 'name' => 'Indian Rupee',
  300. 'symbol' => '₹',
  301. 'currency_position' => CurrencyPositionEnum::RIGHT->value,
  302. ]);
  303. $channel = Channel::factory()->create();
  304. $channel->currencies()->sync(Currency::all()->pluck('id')->toArray());
  305. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  306. core()->setCurrentChannel($channel);
  307. // Act
  308. $formattedPrice = core()->formatPrice($price, $indianCurrency->code);
  309. // Assert
  310. expect($formattedPrice)->toBe($price.$indianCurrency->symbol);
  311. });
  312. it('should format the price based on the mentioned currency and place the symbol on the right side with space', function () {
  313. // Arrange
  314. $indianCurrency = Currency::factory()->create([
  315. 'code' => 'INR',
  316. 'name' => 'Indian Rupee',
  317. 'symbol' => '₹',
  318. 'currency_position' => CurrencyPositionEnum::RIGHT_WITH_SPACE->value,
  319. ]);
  320. $channel = Channel::factory()->create();
  321. $channel->currencies()->sync(Currency::all()->pluck('id')->toArray());
  322. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  323. core()->setCurrentChannel($channel);
  324. // Act
  325. $formattedPrice = core()->formatPrice($price, $indianCurrency->code);
  326. // Assert
  327. expect($formattedPrice)->toBe($price.' '.$indianCurrency->symbol);
  328. });
  329. it('should format the price based on the mentioned currency and place the code on the left side if the symbol is not present', function () {
  330. // Arrange
  331. $indianCurrency = Currency::factory()->create([
  332. 'code' => 'INR',
  333. 'name' => 'Indian Rupee',
  334. 'symbol' => '',
  335. 'currency_position' => CurrencyPositionEnum::LEFT->value,
  336. ]);
  337. $channel = Channel::factory()->create();
  338. $channel->currencies()->sync(Currency::all()->pluck('id')->toArray());
  339. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  340. core()->setCurrentChannel($channel);
  341. // Act
  342. $formattedPrice = core()->formatPrice($price, $indianCurrency->code);
  343. // Assert
  344. expect($formattedPrice)->toBe($indianCurrency->code.$price);
  345. });
  346. it('should format the price based on the mentioned currency and place the code on the left side with space if the symbol is not present', function () {
  347. // Arrange
  348. $indianCurrency = Currency::factory()->create([
  349. 'code' => 'INR',
  350. 'name' => 'Indian Rupee',
  351. 'symbol' => '',
  352. 'currency_position' => CurrencyPositionEnum::LEFT_WITH_SPACE->value,
  353. ]);
  354. $channel = Channel::factory()->create();
  355. $channel->currencies()->sync(Currency::all()->pluck('id')->toArray());
  356. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  357. core()->setCurrentChannel($channel);
  358. // Act
  359. $formattedPrice = core()->formatPrice($price, $indianCurrency->code);
  360. // Assert
  361. expect($formattedPrice)->toBe($indianCurrency->code.' '.$price);
  362. });
  363. it('should format the price based on the mentioned currency and place the code on the right side if the symbol is not present', function () {
  364. // Arrange
  365. $indianCurrency = Currency::factory()->create([
  366. 'code' => 'INR',
  367. 'name' => 'Indian Rupee',
  368. 'symbol' => '',
  369. 'currency_position' => CurrencyPositionEnum::RIGHT->value,
  370. ]);
  371. $channel = Channel::factory()->create();
  372. $channel->currencies()->sync(Currency::all()->pluck('id')->toArray());
  373. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  374. core()->setCurrentChannel($channel);
  375. // Act
  376. $formattedPrice = core()->formatPrice($price, $indianCurrency->code);
  377. // Assert
  378. expect($formattedPrice)->toBe($price.$indianCurrency->code);
  379. });
  380. it('should format the price based on the mentioned currency and place the code on the right side with space if the symbol is not present', function () {
  381. // Arrange
  382. $indianCurrency = Currency::factory()->create([
  383. 'code' => 'INR',
  384. 'name' => 'Indian Rupee',
  385. 'symbol' => '',
  386. 'currency_position' => CurrencyPositionEnum::RIGHT_WITH_SPACE->value,
  387. ]);
  388. $channel = Channel::factory()->create();
  389. $channel->currencies()->sync(Currency::all()->pluck('id')->toArray());
  390. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  391. core()->setCurrentChannel($channel);
  392. // Act
  393. $formattedPrice = core()->formatPrice($price, $indianCurrency->code);
  394. // Assert
  395. expect($formattedPrice)->toBe($price.' '.$indianCurrency->code);
  396. });
  397. it('should format the base price and place the symbol on the left side', function () {
  398. // Arrange
  399. $indianCurrency = Currency::factory()->create([
  400. 'code' => 'INR',
  401. 'name' => 'Indian Rupee',
  402. 'symbol' => '₹',
  403. 'currency_position' => CurrencyPositionEnum::LEFT->value,
  404. ]);
  405. config()->set('app.currency', $indianCurrency->code);
  406. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  407. // Act
  408. $formattedPrice = core()->formatBasePrice($price);
  409. // Assert
  410. expect($formattedPrice)->toBe($indianCurrency->symbol.$price);
  411. });
  412. it('should format the base price and place the symbol on the left side with space', function () {
  413. // Arrange
  414. $indianCurrency = Currency::factory()->create([
  415. 'code' => 'INR',
  416. 'name' => 'Indian Rupee',
  417. 'symbol' => '₹',
  418. 'currency_position' => CurrencyPositionEnum::LEFT_WITH_SPACE->value,
  419. ]);
  420. config()->set('app.currency', $indianCurrency->code);
  421. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  422. // Act
  423. $formattedPrice = core()->formatBasePrice($price);
  424. // Assert
  425. expect($formattedPrice)->toBe($indianCurrency->symbol.' '.$price);
  426. });
  427. it('should format the base price and place the symbol on the right side', function () {
  428. // Arrange
  429. $indianCurrency = Currency::factory()->create([
  430. 'code' => 'INR',
  431. 'name' => 'Indian Rupee',
  432. 'symbol' => '₹',
  433. 'currency_position' => CurrencyPositionEnum::RIGHT->value,
  434. ]);
  435. config()->set('app.currency', $indianCurrency->code);
  436. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  437. // Act
  438. $formattedPrice = core()->formatBasePrice($price);
  439. // Assert
  440. expect($formattedPrice)->toBe($price.$indianCurrency->symbol);
  441. });
  442. it('should format the base price and place the symbol on the right side with space', function () {
  443. // Arrange
  444. $indianCurrency = Currency::factory()->create([
  445. 'code' => 'INR',
  446. 'name' => 'Indian Rupee',
  447. 'symbol' => '₹',
  448. 'currency_position' => CurrencyPositionEnum::RIGHT_WITH_SPACE->value,
  449. ]);
  450. config()->set('app.currency', $indianCurrency->code);
  451. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  452. // Act
  453. $formattedPrice = core()->formatBasePrice($price);
  454. // Assert
  455. expect($formattedPrice)->toBe($price.' '.$indianCurrency->symbol);
  456. });
  457. it('should format the base price and place the code on the left side if symbol is not present', function () {
  458. // Arrange
  459. $indianCurrency = Currency::factory()->create([
  460. 'code' => 'INR',
  461. 'name' => 'Indian Rupee',
  462. 'symbol' => '',
  463. 'currency_position' => CurrencyPositionEnum::LEFT->value,
  464. ]);
  465. config()->set('app.currency', $indianCurrency->code);
  466. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  467. // Act
  468. $formattedPrice = core()->formatBasePrice($price);
  469. // Assert
  470. expect($formattedPrice)->toBe($indianCurrency->code.$price);
  471. });
  472. it('should format the base price and place the code on the left side with space if symbol is not present', function () {
  473. // Arrange
  474. $indianCurrency = Currency::factory()->create([
  475. 'code' => 'INR',
  476. 'name' => 'Indian Rupee',
  477. 'symbol' => '',
  478. 'currency_position' => CurrencyPositionEnum::LEFT_WITH_SPACE->value,
  479. ]);
  480. config()->set('app.currency', $indianCurrency->code);
  481. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  482. // Act
  483. $formattedPrice = core()->formatBasePrice($price);
  484. // Assert
  485. expect($formattedPrice)->toBe($indianCurrency->code.' '.$price);
  486. });
  487. it('should format the base price and place the code on the right side if symbol is not present', function () {
  488. // Arrange
  489. $indianCurrency = Currency::factory()->create([
  490. 'code' => 'INR',
  491. 'name' => 'Indian Rupee',
  492. 'symbol' => '',
  493. 'currency_position' => CurrencyPositionEnum::RIGHT->value,
  494. ]);
  495. config()->set('app.currency', $indianCurrency->code);
  496. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  497. // Act
  498. $formattedPrice = core()->formatBasePrice($price);
  499. // Assert
  500. expect($formattedPrice)->toBe($price.$indianCurrency->code);
  501. });
  502. it('should format the base price and place the code on the right side with space if symbol is not present', function () {
  503. // Arrange
  504. $indianCurrency = Currency::factory()->create([
  505. 'code' => 'INR',
  506. 'name' => 'Indian Rupee',
  507. 'symbol' => '',
  508. 'currency_position' => CurrencyPositionEnum::RIGHT_WITH_SPACE->value,
  509. ]);
  510. config()->set('app.currency', $indianCurrency->code);
  511. $price = number_format(fake()->randomFloat(min: 1, max: 500), $indianCurrency->decimal);
  512. // Act
  513. $formattedPrice = core()->formatBasePrice($price);
  514. // Assert
  515. expect($formattedPrice)->toBe($price.' '.$indianCurrency->code);
  516. });