it('sends the config when set', () => { sinon.stub(config, 'get').withArgs('fxaConfig').returns('my-config'); mockWindow .expects('fetch') .withArgs(`${apiHost}/api/v3/accounts/login/?config=my-config&lang=fr`) .once() .returns(mockResponse()); return api.login({ api: { lang: 'fr' }, code: 'my-code', state: 'my-state' }) .then(() => mockWindow.verify()); });
it('sends the code and state', () => { mockWindow .expects('fetch') .withArgs('https://addons.mozilla.org/api/v3/internal/accounts/login/?lang=en-US', { body: '{"code":"my-code","state":"my-state"}', credentials: 'include', headers: {'Content-type': 'application/json'}, method: 'post', }) .once() .returns(mockResponse()); return api.login({api: {}, code: 'my-code', state: 'my-state'}).then((apiResponse) => { assert.strictEqual(apiResponse, response); mockWindow.verify(); }); });
return ({api, location, router}) => { const { code, state } = location.query; if (code && state) { return login({api, code, state}) .then(({token}) => { dispatch(setJWT(token)); cookie.save(config.get('cookieName'), token, { path: '/', secure: true, maxAge: config.get('cookieMaxAge'), }); router.push('/search'); }); } return Promise.resolve(); };
it('sends the code and state', () => { mockWindow .expects('fetch') .withArgs(`${apiHost}/api/v3/accounts/login/?lang=en-US`, { body: '{"code":"my-code","state":"my-state"}', credentials: 'include', headers: { 'Content-type': 'application/json' }, method: 'POST', }) .once() .returns(mockResponse()); return api.login({ api: { lang: 'en-US' }, code: 'my-code', state: 'my-state' }) .then((apiResponse) => { expect(apiResponse).toBe(response); mockWindow.verify(); }); });