-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace updateCurrentAccount() with refreshSession() (#3910)
Replace updateCurrentAccount() with resumeSession()
- Loading branch information
Showing
9 changed files
with
15 additions
and
257 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1302,177 +1302,6 @@ describe('session', () => { | |
`) | ||
}) | ||
|
||
it('updates current account', () => { | ||
let state = getInitialState([]) | ||
|
||
const agent1 = new BskyAgent({service: 'https://alice.com'}) | ||
agent1.session = { | ||
did: 'alice-did', | ||
handle: 'alice.test', | ||
accessJwt: 'alice-access-jwt-1', | ||
refreshJwt: 'alice-refresh-jwt-1', | ||
} | ||
state = run(state, [ | ||
{ | ||
type: 'switched-to-account', | ||
newAgent: agent1, | ||
newAccount: agentToSessionAccountOrThrow(agent1), | ||
}, | ||
]) | ||
expect(state.accounts.length).toBe(1) | ||
expect(state.accounts[0].accessJwt).toBe('alice-access-jwt-1') | ||
expect(state.currentAgentState.did).toBe('alice-did') | ||
|
||
state = run(state, [ | ||
{ | ||
type: 'updated-current-account', | ||
updatedFields: { | ||
email: '[email protected]', | ||
emailConfirmed: false, | ||
}, | ||
}, | ||
]) | ||
expect(state.accounts.length).toBe(1) | ||
expect(state.accounts[0].email).toBe('[email protected]') | ||
expect(state.accounts[0].emailConfirmed).toBe(false) | ||
expect(state.currentAgentState.did).toBe('alice-did') | ||
expect(printState(state)).toMatchInlineSnapshot(` | ||
{ | ||
"accounts": [ | ||
{ | ||
"accessJwt": "alice-access-jwt-1", | ||
"deactivated": false, | ||
"did": "alice-did", | ||
"email": "[email protected]", | ||
"emailAuthFactor": false, | ||
"emailConfirmed": false, | ||
"handle": "alice.test", | ||
"pdsUrl": undefined, | ||
"refreshJwt": "alice-refresh-jwt-1", | ||
"service": "https://alice.com/", | ||
}, | ||
], | ||
"currentAgentState": { | ||
"agent": { | ||
"service": "https://alice.com/", | ||
}, | ||
"did": "alice-did", | ||
}, | ||
"needsPersist": true, | ||
} | ||
`) | ||
|
||
state = run(state, [ | ||
{ | ||
type: 'updated-current-account', | ||
updatedFields: { | ||
handle: 'alice-updated.test', | ||
}, | ||
}, | ||
]) | ||
expect(state.accounts.length).toBe(1) | ||
expect(state.accounts[0].handle).toBe('alice-updated.test') | ||
expect(state.currentAgentState.did).toBe('alice-did') | ||
expect(printState(state)).toMatchInlineSnapshot(` | ||
{ | ||
"accounts": [ | ||
{ | ||
"accessJwt": "alice-access-jwt-1", | ||
"deactivated": false, | ||
"did": "alice-did", | ||
"email": "[email protected]", | ||
"emailAuthFactor": false, | ||
"emailConfirmed": false, | ||
"handle": "alice-updated.test", | ||
"pdsUrl": undefined, | ||
"refreshJwt": "alice-refresh-jwt-1", | ||
"service": "https://alice.com/", | ||
}, | ||
], | ||
"currentAgentState": { | ||
"agent": { | ||
"service": "https://alice.com/", | ||
}, | ||
"did": "alice-did", | ||
}, | ||
"needsPersist": true, | ||
} | ||
`) | ||
|
||
const agent2 = new BskyAgent({service: 'https://bob.com'}) | ||
agent2.session = { | ||
did: 'bob-did', | ||
handle: 'bob.test', | ||
accessJwt: 'bob-access-jwt-1', | ||
refreshJwt: 'bob-refresh-jwt-1', | ||
} | ||
state = run(state, [ | ||
{ | ||
// Switch to Bob. | ||
type: 'switched-to-account', | ||
newAgent: agent2, | ||
newAccount: agentToSessionAccountOrThrow(agent2), | ||
}, | ||
{ | ||
// Update Bob. | ||
type: 'updated-current-account', | ||
updatedFields: { | ||
handle: 'bob-updated.test', | ||
}, | ||
}, | ||
{ | ||
// Switch back to Alice. | ||
type: 'switched-to-account', | ||
newAgent: agent1, | ||
newAccount: agentToSessionAccountOrThrow(agent1), | ||
}, | ||
{ | ||
// Update Alice. | ||
type: 'updated-current-account', | ||
updatedFields: { | ||
handle: 'alice-updated-2.test', | ||
}, | ||
}, | ||
]) | ||
expect(printState(state)).toMatchInlineSnapshot(` | ||
{ | ||
"accounts": [ | ||
{ | ||
"accessJwt": "alice-access-jwt-1", | ||
"deactivated": false, | ||
"did": "alice-did", | ||
"email": undefined, | ||
"emailAuthFactor": false, | ||
"emailConfirmed": false, | ||
"handle": "alice-updated-2.test", | ||
"pdsUrl": undefined, | ||
"refreshJwt": "alice-refresh-jwt-1", | ||
"service": "https://alice.com/", | ||
}, | ||
{ | ||
"accessJwt": "bob-access-jwt-1", | ||
"deactivated": false, | ||
"did": "bob-did", | ||
"email": undefined, | ||
"emailAuthFactor": false, | ||
"emailConfirmed": false, | ||
"handle": "bob-updated.test", | ||
"pdsUrl": undefined, | ||
"refreshJwt": "bob-refresh-jwt-1", | ||
"service": "https://bob.com/", | ||
}, | ||
], | ||
"currentAgentState": { | ||
"agent": { | ||
"service": "https://alice.com/", | ||
}, | ||
"did": "alice-did", | ||
}, | ||
"needsPersist": true, | ||
} | ||
`) | ||
}) | ||
|
||
it('replaces local accounts with synced accounts', () => { | ||
let state = getInitialState([]) | ||
|
||
|
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
Oops, something went wrong.