diff --git a/src/settings-onboarding-page.js b/src/settings-onboarding-page.js index 4c90d58c..2763e014 100644 --- a/src/settings-onboarding-page.js +++ b/src/settings-onboarding-page.js @@ -82,7 +82,7 @@ async function pollHosted(generation){ } catch(e){ if(generation!==hostedGeneration)return; hostedFlow=false; - say('hosted-service-result','GitHub sign-in failed: '+(e.message==='denied'?'Sign-in was not approved. Click Sign in with GitHub to try again.':e.message==='expired'?'The sign-in code expired. Click Sign in with GitHub to get a new code.':e.message)); + say('hosted-service-result','GitHub sign-in failed: '+(e.message==='denied'?'Sign-in was not approved. Click Sign in with GitHub to try again.':e.message==='expired'?'The sign-in code expired. Click Sign in with GitHub to get a new code.':e.message==='rate_limited'?'The card service received too many sign-in requests. Wait a while before signing in again.':e.message)); } } load(); diff --git a/test/settings-hosted-rate-feedback.test.js b/test/settings-hosted-rate-feedback.test.js new file mode 100644 index 00000000..a93134b4 --- /dev/null +++ b/test/settings-hosted-rate-feedback.test.js @@ -0,0 +1,13 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {runInNewContext} from 'node:vm'; +import {SERVICE_SCRIPT} from '../src/settings-onboarding-page.js'; +test('hosted sign-in rate limit explains why the user should wait',async()=>{ + const nodes=new Map();const get=id=>{if(!nodes.has(id))nodes.set(id,{value:'https://cards.example',hidden:true,addEventListener(k,fn){this[k]=fn},setAttribute(){},replaceChildren(){}});return nodes.get(id)}; + const say=(id,text)=>get(id).textContent=text; + const start=SERVICE_SCRIPT.indexOf('async function pollHosted(');const end=SERVICE_SCRIPT.lastIndexOf('load();'); + const context={$:get,say,hostedFlow:true,hostedGeneration:1,api:async()=>({status:'rate_limited'}),load(){throw Error('should not load after rate limit')}}; + runInNewContext(SERVICE_SCRIPT.slice(start,end),context);await context.pollHosted(1); + assert.equal(get('hosted-service-result').textContent,'GitHub sign-in failed: The card service received too many sign-in requests. Wait a while before signing in again.'); + assert.equal(context.hostedFlow,false); +});