/* eslint-env jest */ import { balanceNote, repeatQuestion } from '../ai-runs'; describe('asking before an AI action runs again', () => { it('asks only for the action that already ran on the page today', () => { expect(repeatQuestion('fix', ['faq'], 10, 'Post')).toBeNull(); expect(repeatQuestion('faq', ['faq'], 10, 'Post')).toBe( 'You ran the FAQ on this post today. Running it again costs 10 credits more. Run it again?' ); }); it('tells the snippet and the content rewrite apart', () => { expect(repeatQuestion('rewrite', ['fix'], 60, 'Page')).toBeNull(); expect(repeatQuestion('fix', ['fix', 'rewrite'], 10, 'Product')).toBe( 'You ran Fix with AI on this product today. Running it again costs 10 credits more. Run it again?' ); }); }); describe('the balance beside the price', () => { it('says nothing while the balance is unknown', () => { expect(balanceNote(undefined, 10)).toBe(''); expect(balanceNote(null, 10)).toBe(''); }); it('says what is left, and when it does not cover the run', () => { expect(balanceNote(245, 60)).toBe(' You have 245 credits.'); expect(balanceNote(60, 60)).toBe(' You have 60 credits.'); expect(balanceNote(35, 60)).toBe(' You have 35, not enough for this run.'); }); });