apply eslint and prettier rules

This commit is contained in:
Sebastian Sdorra
2019-10-21 10:57:56 +02:00
parent 85773186db
commit 4bb8e6153b
227 changed files with 1147 additions and 4076 deletions

View File

@@ -35,10 +35,7 @@ import reducer, {
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import fetchMock from "fetch-mock";
import {
FETCH_INDEXRESOURCES_PENDING,
FETCH_INDEXRESOURCES_SUCCESS
} from "./indexResource";
import { FETCH_INDEXRESOURCES_PENDING, FETCH_INDEXRESOURCES_SUCCESS } from "./indexResource";
const me = {
name: "tricia",
@@ -143,11 +140,9 @@ describe("auth actions", () => {
const store = mockStore({});
return store
.dispatch(login("/auth/access_token", "tricia", "secret123"))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
return store.dispatch(login("/auth/access_token", "tricia", "secret123")).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
it("should dispatch login failure", () => {
@@ -156,14 +151,12 @@ describe("auth actions", () => {
});
const store = mockStore({});
return store
.dispatch(login("/auth/access_token", "tricia", "secret123"))
.then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual(LOGIN_PENDING);
expect(actions[1].type).toEqual(LOGIN_FAILURE);
expect(actions[1].payload).toBeDefined();
});
return store.dispatch(login("/auth/access_token", "tricia", "secret123")).then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual(LOGIN_PENDING);
expect(actions[1].type).toEqual(LOGIN_FAILURE);
expect(actions[1].payload).toBeDefined();
});
});
it("should dispatch fetch me success", () => {
@@ -296,9 +289,7 @@ describe("auth actions", () => {
const store = mockStore({});
return store.dispatch(logout("/auth/access_token")).then(() => {
expect(window.location.assign.mock.calls[0][0]).toBe(
"http://example.com/cas/logout"
);
expect(window.location.assign.mock.calls[0][0]).toBe("http://example.com/cas/logout");
expect(store.getActions()).toEqual(expectedActions);
});
});

View File

@@ -149,11 +149,7 @@ const callFetchMe = (link: string): Promise<Me> => {
});
};
export const login = (
loginLink: string,
username: string,
password: string
) => {
export const login = (loginLink: string, username: string, password: string) => {
const login_data = {
cookie: true,
grant_type: "password",

View File

@@ -18,10 +18,8 @@ describe("change password", () => {
}
});
changePassword(CHANGE_PASSWORD_URL, oldPassword, newPassword).then(
content => {
done();
}
);
changePassword(CHANGE_PASSWORD_URL, oldPassword, newPassword).then(content => {
done();
});
});
});

View File

@@ -1,12 +1,7 @@
import { apiClient } from "@scm-manager/ui-components";
export const CONTENT_TYPE_PASSWORD_CHANGE =
"application/vnd.scmm-passwordChange+json;v=2";
export function changePassword(
url: string,
oldPassword: string,
newPassword: string
) {
export const CONTENT_TYPE_PASSWORD_CHANGE = "application/vnd.scmm-passwordChange+json;v=2";
export function changePassword(url: string, oldPassword: string, newPassword: string) {
return apiClient
.put(
url,

View File

@@ -12,13 +12,9 @@ function extractIdentifierFromFailure(action: Action) {
return identifier;
}
function removeAllEntriesOfIdentifierFromState(
state: object,
payload: any,
identifier: string
) {
function removeAllEntriesOfIdentifierFromState(state: object, payload: any, identifier: string) {
const newState = {};
for (let failureType in state) {
for (const failureType in state) {
if (failureType !== identifier && !failureType.startsWith(identifier)) {
newState[failureType] = state[failureType];
}
@@ -28,7 +24,7 @@ function removeAllEntriesOfIdentifierFromState(
function removeFromState(state: object, identifier: string) {
const newState = {};
for (let failureType in state) {
for (const failureType in state) {
if (failureType !== identifier) {
newState[failureType] = state[failureType];
}
@@ -62,23 +58,14 @@ export default function reducer(
if (action.itemId) {
identifier += "/" + action.itemId;
}
if (action.payload)
return removeAllEntriesOfIdentifierFromState(
state,
action.payload,
identifier
);
if (action.payload) return removeAllEntriesOfIdentifierFromState(state, action.payload, identifier);
else return removeFromState(state, identifier);
}
}
return state;
}
export function getFailure(
state: object,
actionType: string,
itemId?: string | number
) {
export function getFailure(state: object, actionType: string, itemId?: string | number) {
if (state.failure) {
let identifier = actionType;
if (itemId) {

View File

@@ -178,10 +178,7 @@ describe("index resource", () => {
});
it("should store the index resources on FETCH_INDEXRESOURCES_SUCCESS", () => {
const newState = reducer(
{},
fetchIndexResourcesSuccess(indexResourcesAuthenticated)
);
const newState = reducer({}, fetchIndexResourcesSuccess(indexResourcesAuthenticated));
expect(newState.links).toBe(indexResourcesAuthenticated._links);
});
});
@@ -231,9 +228,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getUiPluginsLink(state)).toBe(
"http://localhost:8081/scm/api/v2/ui/plugins"
);
expect(getUiPluginsLink(state)).toBe("http://localhost:8081/scm/api/v2/ui/plugins");
});
it("should return ui plugins links when unauthenticated and has permission to see it", () => {
@@ -242,9 +237,7 @@ describe("index resource", () => {
links: indexResourcesUnauthenticated._links
}
};
expect(getUiPluginsLink(state)).toBe(
"http://localhost:8081/scm/api/v2/ui/plugins"
);
expect(getUiPluginsLink(state)).toBe("http://localhost:8081/scm/api/v2/ui/plugins");
});
// me link
@@ -273,9 +266,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getLogoutLink(state)).toBe(
"http://localhost:8081/scm/api/v2/auth/access_token"
);
expect(getLogoutLink(state)).toBe("http://localhost:8081/scm/api/v2/auth/access_token");
});
it("should return undefined for logout link when unauthenticated or has not permission to see it", () => {
@@ -294,9 +285,7 @@ describe("index resource", () => {
links: indexResourcesUnauthenticated._links
}
};
expect(getLoginLink(state)).toBe(
"http://localhost:8081/scm/api/v2/auth/access_token"
);
expect(getLoginLink(state)).toBe("http://localhost:8081/scm/api/v2/auth/access_token");
});
it("should return undefined for login link when authenticated or has not permission to see it", () => {
@@ -315,9 +304,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getUsersLink(state)).toBe(
"http://localhost:8081/scm/api/v2/users/"
);
expect(getUsersLink(state)).toBe("http://localhost:8081/scm/api/v2/users/");
});
it("should return undefined for users link when unauthenticated or has not permission to see it", () => {
@@ -336,9 +323,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getGroupsLink(state)).toBe(
"http://localhost:8081/scm/api/v2/groups/"
);
expect(getGroupsLink(state)).toBe("http://localhost:8081/scm/api/v2/groups/");
});
it("should return undefined for groups link when unauthenticated or has not permission to see it", () => {
@@ -357,9 +342,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getConfigLink(state)).toBe(
"http://localhost:8081/scm/api/v2/config"
);
expect(getConfigLink(state)).toBe("http://localhost:8081/scm/api/v2/config");
});
it("should return undefined for config link when unauthenticated or has not permission to see it", () => {
@@ -378,9 +361,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getRepositoriesLink(state)).toBe(
"http://localhost:8081/scm/api/v2/repositories/"
);
expect(getRepositoriesLink(state)).toBe("http://localhost:8081/scm/api/v2/repositories/");
});
it("should return config for repositories link when unauthenticated or has not permission to see it", () => {
@@ -399,9 +380,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getHgConfigLink(state)).toBe(
"http://localhost:8081/scm/api/v2/config/hg"
);
expect(getHgConfigLink(state)).toBe("http://localhost:8081/scm/api/v2/config/hg");
});
it("should return config for hgConfig link when unauthenticated or has not permission to see it", () => {
@@ -420,9 +399,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getGitConfigLink(state)).toBe(
"http://localhost:8081/scm/api/v2/config/git"
);
expect(getGitConfigLink(state)).toBe("http://localhost:8081/scm/api/v2/config/git");
});
it("should return config for gitConfig link when unauthenticated or has not permission to see it", () => {
@@ -441,9 +418,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getSvnConfigLink(state)).toBe(
"http://localhost:8081/scm/api/v2/config/svn"
);
expect(getSvnConfigLink(state)).toBe("http://localhost:8081/scm/api/v2/config/svn");
});
it("should return config for svnConfig link when unauthenticated or has not permission to see it", () => {
@@ -462,9 +437,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getLinkCollection(state, "autocomplete")).toEqual(
indexResourcesAuthenticated._links.autocomplete
);
expect(getLinkCollection(state, "autocomplete")).toEqual(indexResourcesAuthenticated._links.autocomplete);
});
it("should return user autocomplete link", () => {
@@ -473,9 +446,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getUserAutoCompleteLink(state)).toEqual(
"http://localhost:8081/scm/api/v2/autocomplete/users"
);
expect(getUserAutoCompleteLink(state)).toEqual("http://localhost:8081/scm/api/v2/autocomplete/users");
});
it("should return group autocomplete link", () => {
@@ -484,9 +455,7 @@ describe("index resource", () => {
links: indexResourcesAuthenticated._links
}
};
expect(getGroupAutoCompleteLink(state)).toEqual(
"http://localhost:8081/scm/api/v2/autocomplete/groups"
);
expect(getGroupAutoCompleteLink(state)).toEqual("http://localhost:8081/scm/api/v2/autocomplete/groups");
});
});
});

View File

@@ -176,9 +176,7 @@ export function getLoginInfoLink(state: object) {
}
export function getUserAutoCompleteLink(state: object): string {
const link = getLinkCollection(state, "autocomplete").find(
i => i.name === "users"
);
const link = getLinkCollection(state, "autocomplete").find(i => i.name === "users");
if (link) {
return link.href;
}
@@ -186,9 +184,7 @@ export function getUserAutoCompleteLink(state: object): string {
}
export function getGroupAutoCompleteLink(state: object): string {
const link = getLinkCollection(state, "autocomplete").find(
i => i.name === "groups"
);
const link = getLinkCollection(state, "autocomplete").find(i => i.name === "groups");
if (link) {
return link.href;
}

View File

@@ -2,15 +2,11 @@ import { Action } from "@scm-manager/ui-types";
import * as types from "./types";
const PENDING_SUFFIX = "_" + types.PENDING_SUFFIX;
const RESET_ACTIONTYPES = [
types.SUCCESS_SUFFIX,
types.FAILURE_SUFFIX,
types.RESET_SUFFIX
];
const RESET_ACTIONTYPES = [types.SUCCESS_SUFFIX, types.FAILURE_SUFFIX, types.RESET_SUFFIX];
function removeFromState(state: object, identifier: string) {
let newState = {};
for (let childType in state) {
const newState = {};
for (const childType in state) {
if (childType !== identifier) {
newState[childType] = state[childType];
}
@@ -18,13 +14,9 @@ function removeFromState(state: object, identifier: string) {
return newState;
}
function removeAllEntriesOfIdentifierFromState(
state: object,
payload: any,
identifier: string
) {
function removeAllEntriesOfIdentifierFromState(state: object, payload: any, identifier: string) {
const newState = {};
for (let childType in state) {
for (const childType in state) {
if (childType !== identifier && !childType.startsWith(identifier)) {
newState[childType] = state[childType];
}
@@ -63,12 +55,7 @@ export default function reducer(
if (action.itemId) {
identifier += "/" + action.itemId;
}
if (action.payload)
return removeAllEntriesOfIdentifierFromState(
state,
action.payload,
identifier
);
if (action.payload) return removeAllEntriesOfIdentifierFromState(state, action.payload, identifier);
else return removeFromState(state, identifier);
}
}
@@ -76,11 +63,7 @@ export default function reducer(
return state;
}
export function isPending(
state: object,
actionType: string,
itemId?: string | number
) {
export function isPending(state: object, actionType: string, itemId?: string | number) {
let type = actionType;
if (itemId) {
type += "/" + itemId;