|
| 1 | +const { expect } = require('chai'); |
| 2 | +const { I18n } = require('@grammyjs/i18n'); |
| 3 | +const { getOrderTitleMessage } = require('../../bot/ordersActions'); |
| 4 | + |
| 5 | +// Real i18n context so the test exercises the actual locale strings and |
| 6 | +// their ${amount} interpolation (the part that regressed in PR #770). |
| 7 | +const i18nCtx = new I18n({ |
| 8 | + locale: 'en', |
| 9 | + defaultLanguageOnMissing: true, |
| 10 | + directory: 'locales', |
| 11 | +}).createContext('en', {}); |
| 12 | + |
| 13 | +describe('getOrderTitleMessage', () => { |
| 14 | + const anonymousUser: any = { username: 'alice', show_username: false }; |
| 15 | + const publicUser: any = { username: 'alice', show_username: true }; |
| 16 | + |
| 17 | + describe('fixed orders (amount set, price not from API)', () => { |
| 18 | + it('shows the sats amount when selling', () => { |
| 19 | + const title = getOrderTitleMessage( |
| 20 | + anonymousUser, |
| 21 | + 'sell', |
| 22 | + 100, |
| 23 | + 'USD', |
| 24 | + false, |
| 25 | + i18nCtx, |
| 26 | + ); |
| 27 | + |
| 28 | + expect(title).to.equal('Selling 100 sats'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('shows the sats amount when buying', () => { |
| 32 | + const title = getOrderTitleMessage( |
| 33 | + anonymousUser, |
| 34 | + 'buy', |
| 35 | + 100, |
| 36 | + 'USD', |
| 37 | + false, |
| 38 | + i18nCtx, |
| 39 | + ); |
| 40 | + |
| 41 | + expect(title).to.equal('Buying 100 sats'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('shows the username and the sats amount when the user shows their name', () => { |
| 45 | + const title = getOrderTitleMessage( |
| 46 | + publicUser, |
| 47 | + 'sell', |
| 48 | + 100, |
| 49 | + 'USD', |
| 50 | + false, |
| 51 | + i18nCtx, |
| 52 | + ); |
| 53 | + |
| 54 | + expect(title).to.equal('@alice is selling 100 sats'); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe('market/range orders (amount is 0, price from API)', () => { |
| 59 | + it('omits the amount when selling', () => { |
| 60 | + const title = getOrderTitleMessage( |
| 61 | + anonymousUser, |
| 62 | + 'sell', |
| 63 | + 0, |
| 64 | + 'USD', |
| 65 | + true, |
| 66 | + i18nCtx, |
| 67 | + ); |
| 68 | + |
| 69 | + expect(title).to.equal('Selling sats'); |
| 70 | + }); |
| 71 | + |
| 72 | + it('omits the amount when buying', () => { |
| 73 | + const title = getOrderTitleMessage( |
| 74 | + anonymousUser, |
| 75 | + 'buy', |
| 76 | + 0, |
| 77 | + 'USD', |
| 78 | + true, |
| 79 | + i18nCtx, |
| 80 | + ); |
| 81 | + |
| 82 | + expect(title).to.equal('Buying sats'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('shows the username but omits the amount when the user shows their name', () => { |
| 86 | + const title = getOrderTitleMessage( |
| 87 | + publicUser, |
| 88 | + 'buy', |
| 89 | + 0, |
| 90 | + 'USD', |
| 91 | + true, |
| 92 | + i18nCtx, |
| 93 | + ); |
| 94 | + |
| 95 | + expect(title).to.equal('@alice is buying sats'); |
| 96 | + }); |
| 97 | + }); |
| 98 | +}); |
0 commit comments