-
-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
accounts: Make
Auth.realm
a URL object, including in state.accounts
.
Changing the `Auth` type implicitly changes the `Account` and `Identity` types, too. Done with an effort to minimize unnecessary follow-on changes in this commit. Here, we don't propagate the realm in its URL form as far toward the eventual consumers of the realm as we'll eventually want to; we'll do that in upcoming commits. Wherever two realm values are compared for equality with `===`, we make sure they are both stringified first. Flow didn't warn about these cases, so we caught them in test failures and by scanning through a full-project search for the term 'realm'.
- Loading branch information
1 parent
1dfec57
commit 8c0cc3f
Showing
35 changed files
with
96 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,8 @@ import * as eg from '../../__tests__/lib/exampleData'; | |
describe('accountsReducer', () => { | ||
describe('REALM_ADD', () => { | ||
describe('on list of identities', () => { | ||
const account1 = eg.makeAccount({ realm: 'https://realm.one.org', apiKey: '' }); | ||
const account2 = eg.makeAccount({ realm: 'https://realm.two.org', apiKey: '' }); | ||
const account1 = eg.makeAccount({ realm: new URL('https://realm.one.org'), apiKey: '' }); | ||
const account2 = eg.makeAccount({ realm: new URL('https://realm.two.org'), apiKey: '' }); | ||
const prevState = deepFreeze([account1, account2]); | ||
const baseAction = deepFreeze({ | ||
type: REALM_ADD, | ||
|
@@ -27,8 +27,8 @@ describe('accountsReducer', () => { | |
}); | ||
|
||
test('if no account with this realm exists, prepend new one, with empty email/apiKey', () => { | ||
const newRealm = 'https://new.realm.org'; | ||
const action = deepFreeze({ ...baseAction, realm: newRealm }); | ||
const newRealm = new URL('https://new.realm.org'); | ||
const action = deepFreeze({ ...baseAction, realm: newRealm.toString() }); | ||
expect(accountsReducer(prevState, action)).toEqual([ | ||
eg.makeAccount({ realm: newRealm, email: '', apiKey: '' }), | ||
account1, | ||
|
@@ -37,7 +37,7 @@ describe('accountsReducer', () => { | |
}); | ||
|
||
test('if account with this realm exists, move to front of list', () => { | ||
const action = deepFreeze({ ...baseAction, realm: account2.realm }); | ||
const action = deepFreeze({ ...baseAction, realm: account2.realm.toString() }); | ||
expect(accountsReducer(prevState, action)).toEqual([account2, account1]); | ||
}); | ||
}); | ||
|
@@ -46,7 +46,7 @@ describe('accountsReducer', () => { | |
const existingAccountBase = eg.makeAccount({}); | ||
const baseAction = deepFreeze({ | ||
type: REALM_ADD, | ||
realm: existingAccountBase.realm, | ||
realm: existingAccountBase.realm.toString(), | ||
zulipFeatureLevel: eg.zulipFeatureLevel, | ||
zulipVersion: eg.zulipVersion, | ||
}); | ||
|
@@ -153,8 +153,8 @@ describe('accountsReducer', () => { | |
}); | ||
|
||
describe('LOGIN_SUCCESS', () => { | ||
const account1 = eg.makeAccount({ email: '', realm: 'https://one.example.org' }); | ||
const account2 = eg.makeAccount({ realm: 'https://two.example.org' }); | ||
const account1 = eg.makeAccount({ email: '', realm: new URL('https://one.example.org') }); | ||
const account2 = eg.makeAccount({ realm: new URL('https://two.example.org') }); | ||
|
||
const prevState = deepFreeze([account1, account2]); | ||
|
||
|
@@ -168,7 +168,7 @@ describe('accountsReducer', () => { | |
type: LOGIN_SUCCESS, | ||
apiKey: newAccount.apiKey, | ||
email: newAccount.email, | ||
realm: newAccount.realm, | ||
realm: newAccount.realm.toString(), | ||
}); | ||
|
||
const expectedState = [{ ...newAccount, zulipVersion: account1.zulipVersion }, account2]; | ||
|
@@ -181,7 +181,7 @@ describe('accountsReducer', () => { | |
test('on login, if account does not exist, add as first item', () => { | ||
const newAccount = eg.makeAccount({ | ||
email: '[email protected]', | ||
realm: 'https://new.realm.org', | ||
realm: new URL('https://new.realm.org'), | ||
zulipVersion: null, | ||
zulipFeatureLevel: null, | ||
}); | ||
|
@@ -190,7 +190,7 @@ describe('accountsReducer', () => { | |
type: LOGIN_SUCCESS, | ||
apiKey: newAccount.apiKey, | ||
email: newAccount.email, | ||
realm: newAccount.realm, | ||
realm: newAccount.realm.toString(), | ||
}); | ||
|
||
const expectedState = [newAccount, account1, account2]; | ||
|
@@ -209,7 +209,7 @@ describe('accountsReducer', () => { | |
const action = deepFreeze({ | ||
type: LOGIN_SUCCESS, | ||
apiKey: newAccount.apiKey, | ||
realm: newAccount.realm, | ||
realm: newAccount.realm.toString(), | ||
email: newAccount.email, | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
* an `Auth`. | ||
*/ | ||
export type Auth = {| | ||
realm: string, | ||
realm: URL, | ||
apiKey: string, | ||
email: string, | ||
|}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ describe('navReducer', () => { | |
const action = deepFreeze({ | ||
type: REHYDRATE, | ||
payload: { | ||
accounts: [{ apiKey: '', realm: 'https://example.com' }], | ||
accounts: [{ apiKey: '', realm: new URL('https://example.com') }], | ||
users: [], | ||
realm: {}, | ||
}, | ||
|
@@ -147,8 +147,8 @@ describe('navReducer', () => { | |
type: REHYDRATE, | ||
payload: { | ||
accounts: [ | ||
{ apiKey: '', realm: 'https://example.com', email: '[email protected]' }, | ||
{ apiKey: '', realm: 'https://example.com', email: '[email protected]' }, | ||
{ apiKey: '', realm: new URL('https://example.com'), email: '[email protected]' }, | ||
{ apiKey: '', realm: new URL('https://example.com'), email: '[email protected]' }, | ||
], | ||
users: [], | ||
realm: {}, | ||
|
@@ -165,7 +165,9 @@ describe('navReducer', () => { | |
const action = deepFreeze({ | ||
type: REHYDRATE, | ||
payload: { | ||
accounts: [{ apiKey: '', realm: 'https://example.com', email: '[email protected]' }], | ||
accounts: [ | ||
{ apiKey: '', realm: new URL('https://example.com'), email: '[email protected]' }, | ||
], | ||
users: [], | ||
realm: {}, | ||
}, | ||
|
Oops, something went wrong.