mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
fix test on the new option for accounts storage
This commit is contained in:
@@ -27,8 +27,7 @@ export class AccountsClient extends AccountsCommon {
|
||||
this.savedHash = window.location.hash;
|
||||
this._initUrlMatching();
|
||||
|
||||
// Determine whether to use local or session storage to storage credentials and anything else.
|
||||
this.storageLocation = (options?.clientStorage === 'session' || Meteor.settings?.public?.packages?.accounts?.clientStorage === 'session') ? window.sessionStorage : Meteor._localStorage;
|
||||
this.initStorageLocation();
|
||||
|
||||
// Defined in localstorage_token.js.
|
||||
this._initLocalStorage();
|
||||
@@ -41,6 +40,17 @@ export class AccountsClient extends AccountsCommon {
|
||||
this._loginCallbacksCalled = false;
|
||||
}
|
||||
|
||||
initStorageLocation(options) {
|
||||
// Determine whether to use local or session storage to storage credentials and anything else.
|
||||
this.storageLocation = (options?.clientStorage === 'session' || Meteor.settings?.public?.packages?.accounts?.clientStorage === 'session') ? window.sessionStorage : Meteor._localStorage;
|
||||
}
|
||||
|
||||
config(options) {
|
||||
super.config(options);
|
||||
|
||||
this.initStorageLocation(options);
|
||||
}
|
||||
|
||||
///
|
||||
/// CURRENT USER
|
||||
///
|
||||
|
||||
@@ -304,21 +304,42 @@ Tinytest.addAsync(
|
||||
}
|
||||
);
|
||||
|
||||
testAsyncMulti('accounts - storage', [
|
||||
function (test, expect) {
|
||||
Accounts.config({ clientStorage: 'session' }) // No need to set the default value
|
||||
test.isTrue(Accounts._options.clientStorage)
|
||||
test.isNotUndefined(sessionStorage.getItem('Meteor.loginToken'))
|
||||
test.isUndefined(localStorage.getItem('Meteor.loginToken'))
|
||||
Accounts.logout()
|
||||
removeTestUser()
|
||||
},
|
||||
function (test, expect) {
|
||||
Accounts.config({ clientStorage: 'local' })
|
||||
test.isFalse(Accounts._options.clientStorage)
|
||||
test.isUndefined(sessionStorage.getItem('Meteor.loginToken'))
|
||||
test.isNotUndefined(localStorage.getItem('Meteor.loginToken'))
|
||||
Accounts.logout()
|
||||
removeTestUser()
|
||||
}
|
||||
])
|
||||
Tinytest.addAsync('accounts - storage',
|
||||
async function(test) {
|
||||
const expectWhenSessionStorage = () => {
|
||||
test.isNotUndefined(sessionStorage.getItem('Meteor.loginToken'));
|
||||
test.isNull(localStorage.getItem('Meteor.loginToken'));
|
||||
};
|
||||
const expectWhenLocalStorage = () => {
|
||||
test.isNotUndefined(localStorage.getItem('Meteor.loginToken'));
|
||||
test.isNull(sessionStorage.getItem('Meteor.loginToken'));
|
||||
};
|
||||
|
||||
const testCases = [{
|
||||
clientStorage: undefined,
|
||||
expectStorage: expectWhenLocalStorage,
|
||||
}, {
|
||||
clientStorage: 'local',
|
||||
expectStorage: expectWhenLocalStorage,
|
||||
}, {
|
||||
clientStorage: 'session',
|
||||
expectStorage: expectWhenSessionStorage,
|
||||
}];
|
||||
for await (const testCase of testCases) {
|
||||
await new Promise(resolve => {
|
||||
sessionStorage.clear();
|
||||
localStorage.clear();
|
||||
|
||||
const { clientStorage, expectStorage } = testCase;
|
||||
Accounts.config({ clientStorage });
|
||||
test.equal(Accounts._options.clientStorage, clientStorage);
|
||||
|
||||
// Login a user and test that tokens are in expected storage
|
||||
logoutAndCreateUser(test, resolve, () => {
|
||||
Accounts.logout();
|
||||
expectStorage();
|
||||
removeTestUser(resolve);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user