test(backend-gitlab): cover gitlab backend integration (#1968)
This commit is contained in:
@ -32,7 +32,7 @@ import {
|
||||
dateParsers,
|
||||
} from 'Lib/stringTemplate';
|
||||
|
||||
class LocalStorageAuthStore {
|
||||
export class LocalStorageAuthStore {
|
||||
storageKey = 'netlify-cms-user';
|
||||
|
||||
retrieve() {
|
||||
@ -200,7 +200,7 @@ function createPreviewUrl(baseUrl, collection, slug, slugConfig, entry) {
|
||||
return `${basePath}/${previewPath}`;
|
||||
}
|
||||
|
||||
class Backend {
|
||||
export class Backend {
|
||||
constructor(implementation, { backendName, authStore = null, config } = {}) {
|
||||
// We can't reliably run this on exit, so we do cleanup on load.
|
||||
this.deleteAnonymousBackup();
|
||||
@ -224,10 +224,10 @@ class Backend {
|
||||
const stored = this.authStore && this.authStore.retrieve();
|
||||
if (stored && stored.backendName === this.backendName) {
|
||||
return Promise.resolve(this.implementation.restoreUser(stored)).then(user => {
|
||||
const newUser = { ...user, backendName: this.backendName };
|
||||
this.user = { ...user, backendName: this.backendName };
|
||||
// return confirmed/rehydrated user object instead of stored
|
||||
this.authStore.store(newUser);
|
||||
return newUser;
|
||||
this.authStore.store(this.user);
|
||||
return this.user;
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
@ -236,9 +236,9 @@ class Backend {
|
||||
updateUserCredentials = updatedCredentials => {
|
||||
const storedUser = this.authStore && this.authStore.retrieve();
|
||||
if (storedUser && storedUser.backendName === this.backendName) {
|
||||
const newUser = { ...storedUser, ...updatedCredentials };
|
||||
this.authStore.store(newUser);
|
||||
return newUser;
|
||||
this.user = { ...storedUser, ...updatedCredentials };
|
||||
this.authStore.store(this.user);
|
||||
return this.user;
|
||||
}
|
||||
};
|
||||
|
||||
@ -248,16 +248,17 @@ class Backend {
|
||||
|
||||
authenticate(credentials) {
|
||||
return this.implementation.authenticate(credentials).then(user => {
|
||||
const newUser = { ...user, backendName: this.backendName };
|
||||
this.user = { ...user, backendName: this.backendName };
|
||||
if (this.authStore) {
|
||||
this.authStore.store(newUser);
|
||||
this.authStore.store(this.user);
|
||||
}
|
||||
return newUser;
|
||||
return this.user;
|
||||
});
|
||||
}
|
||||
|
||||
logout() {
|
||||
return Promise.resolve(this.implementation.logout()).then(() => {
|
||||
this.user = null;
|
||||
if (this.authStore) {
|
||||
this.authStore.logout();
|
||||
}
|
||||
|
Reference in New Issue
Block a user