Skip to content

Commit

Permalink
fix: return fractional prices from commerce.price
Browse files Browse the repository at this point in the history
  • Loading branch information
import-brain committed Oct 9, 2023
1 parent 350dfbf commit d4b6bc7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
7 changes: 5 additions & 2 deletions src/modules/commerce/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,11 @@ export class CommerceModule {
return `${symbol}${0.0}`;
}

// TODO @Shinigami92 2022-11-24: https://github.com/faker-js/faker/issues/350
const randValue = this.faker.number.int({ min, max });
const randValue = this.faker.number.float({
min,
max,
precision: (1 / 10) ** dec,
});

return symbol + randValue.toFixed(dec);
}
Expand Down
66 changes: 33 additions & 33 deletions test/modules/__snapshots__/commerce.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ exports[`commerce > 42 > isbn > with variant 10 and space separators 1`] = `"0 7

exports[`commerce > 42 > isbn > with variant 13 1`] = `"978-0-7917-7551-6"`;

exports[`commerce > 42 > price > noArgs 1`] = `"375.00"`;
exports[`commerce > 42 > price > noArgs 1`] = `"375.16"`;

exports[`commerce > 42 > price > with max 1`] = `"375.00"`;
exports[`commerce > 42 > price > with max 1`] = `"375.16"`;

exports[`commerce > 42 > price > with max option 1`] = `"501.00"`;
exports[`commerce > 42 > price > with max option 1`] = `"501.38"`;

exports[`commerce > 42 > price > with min 1`] = `"406.00"`;
exports[`commerce > 42 > price > with min 1`] = `"405.81"`;

exports[`commerce > 42 > price > with min and max 1`] = `"69.00"`;
exports[`commerce > 42 > price > with min and max 1`] = `"68.72"`;

exports[`commerce > 42 > price > with min and max and decimals 1`] = `"69.0000"`;
exports[`commerce > 42 > price > with min and max and decimals 1`] = `"68.7270"`;

exports[`commerce > 42 > price > with min and max and decimals and symbol 1`] = `"$69.0000"`;
exports[`commerce > 42 > price > with min and max and decimals and symbol 1`] = `"$68.7270"`;

exports[`commerce > 42 > price > with min and max and decimals and symbol option 1`] = `"$69.0000"`;
exports[`commerce > 42 > price > with min and max and decimals and symbol option 1`] = `"$68.7270"`;

exports[`commerce > 42 > price > with min and max and decimals option 1`] = `"69.0000"`;
exports[`commerce > 42 > price > with min and max and decimals option 1`] = `"68.7270"`;

exports[`commerce > 42 > price > with min and max option 1`] = `"69.00"`;
exports[`commerce > 42 > price > with min and max option 1`] = `"68.72"`;

exports[`commerce > 42 > price > with min option 1`] = `"401.00"`;
exports[`commerce > 42 > price > with min option 1`] = `"400.80"`;

exports[`commerce > 42 > product 1`] = `"Pants"`;

Expand All @@ -56,27 +56,27 @@ exports[`commerce > 1211 > isbn > with variant 10 and space separators 1`] = `"1

exports[`commerce > 1211 > isbn > with variant 13 1`] = `"978-1-4872-1906-2"`;

exports[`commerce > 1211 > price > noArgs 1`] = `"929.00"`;
exports[`commerce > 1211 > price > noArgs 1`] = `"928.59"`;

exports[`commerce > 1211 > price > with max 1`] = `"929.00"`;
exports[`commerce > 1211 > price > with max 1`] = `"928.59"`;

exports[`commerce > 1211 > price > with max option 1`] = `"1242.00"`;
exports[`commerce > 1211 > price > with max option 1`] = `"1241.50"`;

exports[`commerce > 1211 > price > with min 1`] = `"933.00"`;
exports[`commerce > 1211 > price > with min 1`] = `"932.09"`;

exports[`commerce > 1211 > price > with min and max 1`] = `"97.00"`;
exports[`commerce > 1211 > price > with min and max 1`] = `"96.42"`;

exports[`commerce > 1211 > price > with min and max and decimals 1`] = `"97.0000"`;
exports[`commerce > 1211 > price > with min and max and decimals 1`] = `"96.4260"`;

exports[`commerce > 1211 > price > with min and max and decimals and symbol 1`] = `"$97.0000"`;
exports[`commerce > 1211 > price > with min and max and decimals and symbol 1`] = `"$96.4260"`;

exports[`commerce > 1211 > price > with min and max and decimals and symbol option 1`] = `"$97.0000"`;
exports[`commerce > 1211 > price > with min and max and decimals and symbol option 1`] = `"$96.4260"`;

exports[`commerce > 1211 > price > with min and max and decimals option 1`] = `"97.0000"`;
exports[`commerce > 1211 > price > with min and max and decimals option 1`] = `"96.4260"`;

exports[`commerce > 1211 > price > with min and max option 1`] = `"97.00"`;
exports[`commerce > 1211 > price > with min and max option 1`] = `"96.42"`;

exports[`commerce > 1211 > price > with min option 1`] = `"932.00"`;
exports[`commerce > 1211 > price > with min option 1`] = `"931.52"`;

exports[`commerce > 1211 > product 1`] = `"Sausages"`;

Expand All @@ -100,27 +100,27 @@ exports[`commerce > 1337 > isbn > with variant 10 and space separators 1`] = `"0

exports[`commerce > 1337 > isbn > with variant 13 1`] = `"978-0-512-25403-0"`;

exports[`commerce > 1337 > price > noArgs 1`] = `"263.00"`;
exports[`commerce > 1337 > price > noArgs 1`] = `"262.76"`;

exports[`commerce > 1337 > price > with max 1`] = `"263.00"`;
exports[`commerce > 1337 > price > with max 1`] = `"262.76"`;

exports[`commerce > 1337 > price > with max option 1`] = `"351.00"`;
exports[`commerce > 1337 > price > with max option 1`] = `"351.06"`;

exports[`commerce > 1337 > price > with min 1`] = `"299.00"`;
exports[`commerce > 1337 > price > with min 1`] = `"298.92"`;

exports[`commerce > 1337 > price > with min and max 1`] = `"63.00"`;
exports[`commerce > 1337 > price > with min and max 1`] = `"63.10"`;

exports[`commerce > 1337 > price > with min and max and decimals 1`] = `"63.0000"`;
exports[`commerce > 1337 > price > with min and max and decimals 1`] = `"63.1012"`;

exports[`commerce > 1337 > price > with min and max and decimals and symbol 1`] = `"$63.0000"`;
exports[`commerce > 1337 > price > with min and max and decimals and symbol 1`] = `"$63.1012"`;

exports[`commerce > 1337 > price > with min and max and decimals and symbol option 1`] = `"$63.0000"`;
exports[`commerce > 1337 > price > with min and max and decimals and symbol option 1`] = `"$63.1012"`;

exports[`commerce > 1337 > price > with min and max and decimals option 1`] = `"63.0000"`;
exports[`commerce > 1337 > price > with min and max and decimals option 1`] = `"63.1012"`;

exports[`commerce > 1337 > price > with min and max option 1`] = `"63.00"`;
exports[`commerce > 1337 > price > with min and max option 1`] = `"63.10"`;

exports[`commerce > 1337 > price > with min option 1`] = `"293.00"`;
exports[`commerce > 1337 > price > with min option 1`] = `"293.01"`;

exports[`commerce > 1337 > product 1`] = `"Ball"`;

Expand Down

0 comments on commit d4b6bc7

Please sign in to comment.