frontend: cleanup

* dummy commit

* cleanup workflows

* setup and run eslint

* add linter to CI

* use eslint for formatting

* reorder rules

* drop editor config
This commit is contained in:
Hayden 2022-09-09 14:46:53 -08:00 committed by GitHub
parent 78fa714297
commit 75c633dcb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
65 changed files with 2048 additions and 641 deletions

View file

@ -1,8 +1,8 @@
import { describe, test, expect } from 'vitest';
import { client, userClient } from './test-utils';
import { describe, test, expect } from "vitest";
import { client, userClient } from "./test-utils";
describe('[GET] /api/v1/status', () => {
test('server should respond', async () => {
describe("[GET] /api/v1/status", () => {
test("server should respond", async () => {
const api = client();
const { response, data } = await api.status();
expect(response.status).toBe(200);
@ -10,23 +10,23 @@ describe('[GET] /api/v1/status', () => {
});
});
describe('first time user workflow (register, login)', () => {
describe("first time user workflow (register, login)", () => {
const api = client();
const userData = {
groupName: 'test-group',
groupName: "test-group",
user: {
email: 'test-user@email.com',
name: 'test-user',
password: 'test-password',
email: "test-user@email.com",
name: "test-user",
password: "test-password",
},
};
test('user should be able to register', async () => {
test("user should be able to register", async () => {
const { response } = await api.register(userData);
expect(response.status).toBe(204);
});
test('user should be able to login', async () => {
test("user should be able to login", async () => {
const { response, data } = await api.login(userData.user.email, userData.user.password);
expect(response.status).toBe(200);
expect(data.token).toBeTruthy();

View file

@ -1,24 +1,24 @@
import { beforeAll, expect } from 'vitest';
import { Requests } from '../../requests';
import { overrideParts } from '../base/urls';
import { PublicApi } from '../public';
import * as config from '../../../test/config';
import { UserApi } from '../user';
import { beforeAll, expect } from "vitest";
import { Requests } from "../../requests";
import { overrideParts } from "../base/urls";
import { PublicApi } from "../public";
import * as config from "../../../test/config";
import { UserApi } from "../user";
export function client() {
overrideParts(config.BASE_URL, '/api/v1');
const requests = new Requests('');
overrideParts(config.BASE_URL, "/api/v1");
const requests = new Requests("");
return new PublicApi(requests);
}
export function userClient(token: string) {
overrideParts(config.BASE_URL, '/api/v1');
const requests = new Requests('', token);
overrideParts(config.BASE_URL, "/api/v1");
const requests = new Requests("", token);
return new UserApi(requests);
}
const cache = {
token: '',
token: "",
};
/*
@ -30,11 +30,11 @@ export async function sharedUserClient(): Promise<UserApi> {
return userClient(cache.token);
}
const testUser = {
groupName: 'test-group',
groupName: "test-group",
user: {
email: '__test__@__test__.com',
name: '__test__',
password: '__test__',
email: "__test__@__test__.com",
name: "__test__",
password: "__test__",
},
};

View file

@ -1,9 +1,9 @@
import { describe, expect, test } from 'vitest';
import { Label } from '../../classes/labels';
import { UserApi } from '../../user';
import { sharedUserClient } from '../test-utils';
import { describe, expect, test } from "vitest";
import { Label } from "../../classes/labels";
import { UserApi } from "../../user";
import { sharedUserClient } from "../test-utils";
describe('locations lifecycle (create, update, delete)', () => {
describe("locations lifecycle (create, update, delete)", () => {
let increment = 0;
/**
@ -14,7 +14,7 @@ describe('locations lifecycle (create, update, delete)', () => {
const { response, data } = await api.labels.create({
name: `__test__.label.name_${increment}`,
description: `__test__.label.description_${increment}`,
color: '',
color: "",
});
expect(response.status).toBe(201);
increment++;
@ -26,13 +26,13 @@ describe('locations lifecycle (create, update, delete)', () => {
return [data, cleanup];
}
test('user should be able to create a label', async () => {
test("user should be able to create a label", async () => {
const api = await sharedUserClient();
const labelData = {
name: 'test-label',
description: 'test-description',
color: '',
name: "test-label",
description: "test-description",
color: "",
};
const { response, data } = await api.labels.create(labelData);
@ -53,14 +53,14 @@ describe('locations lifecycle (create, update, delete)', () => {
expect(deleteResponse.status).toBe(204);
});
test('user should be able to update a label', async () => {
test("user should be able to update a label", async () => {
const api = await sharedUserClient();
const [label, cleanup] = await useLabel(api);
const labelData = {
name: 'test-label',
description: 'test-description',
color: '',
name: "test-label",
description: "test-description",
color: "",
};
const { response, data } = await api.labels.update(label.id, labelData);
@ -78,7 +78,7 @@ describe('locations lifecycle (create, update, delete)', () => {
await cleanup();
});
test('user should be able to delete a label', async () => {
test("user should be able to delete a label", async () => {
const api = await sharedUserClient();
const [label, _] = await useLabel(api);

View file

@ -1,9 +1,9 @@
import { describe, expect, test } from 'vitest';
import { Location } from '../../classes/locations';
import { UserApi } from '../../user';
import { sharedUserClient } from '../test-utils';
import { describe, expect, test } from "vitest";
import { Location } from "../../classes/locations";
import { UserApi } from "../../user";
import { sharedUserClient } from "../test-utils";
describe('locations lifecycle (create, update, delete)', () => {
describe("locations lifecycle (create, update, delete)", () => {
let increment = 0;
/**
@ -26,12 +26,12 @@ describe('locations lifecycle (create, update, delete)', () => {
return [data, cleanup];
}
test('user should be able to create a location', async () => {
test("user should be able to create a location", async () => {
const api = await sharedUserClient();
const locationData = {
name: 'test-location',
description: 'test-description',
name: "test-location",
description: "test-description",
};
const { response, data } = await api.locations.create(locationData);
@ -52,13 +52,13 @@ describe('locations lifecycle (create, update, delete)', () => {
expect(deleteResponse.status).toBe(204);
});
test('user should be able to update a location', async () => {
test("user should be able to update a location", async () => {
const api = await sharedUserClient();
const [location, cleanup] = await useLocation(api);
const updateData = {
name: 'test-location-updated',
description: 'test-description-updated',
name: "test-location-updated",
description: "test-description-updated",
};
const { response } = await api.locations.update(location.id, updateData);
@ -75,7 +75,7 @@ describe('locations lifecycle (create, update, delete)', () => {
await cleanup();
});
test('user should be able to delete a location', async () => {
test("user should be able to delete a location", async () => {
const api = await sharedUserClient();
const [location, _] = await useLocation(api);

View file

@ -1,4 +1,4 @@
import { Requests } from '../../requests';
import { Requests } from "../../requests";
// <
// TGetResult,
// TPostData,

View file

@ -1,24 +1,24 @@
import { describe, expect, it } from 'vitest';
import { route } from '.';
import { describe, expect, it } from "vitest";
import { route } from ".";
describe('UrlBuilder', () => {
it('basic query parameter', () => {
const result = route('/test', { a: 'b' });
expect(result).toBe('/api/v1/test?a=b');
describe("UrlBuilder", () => {
it("basic query parameter", () => {
const result = route("/test", { a: "b" });
expect(result).toBe("/api/v1/test?a=b");
});
it('multiple query parameters', () => {
const result = route('/test', { a: 'b', c: 'd' });
expect(result).toBe('/api/v1/test?a=b&c=d');
it("multiple query parameters", () => {
const result = route("/test", { a: "b", c: "d" });
expect(result).toBe("/api/v1/test?a=b&c=d");
});
it('no query parameters', () => {
const result = route('/test');
expect(result).toBe('/api/v1/test');
it("no query parameters", () => {
const result = route("/test");
expect(result).toBe("/api/v1/test");
});
it('list-like query parameters', () => {
const result = route('/test', { a: ['b', 'c'] });
expect(result).toBe('/api/v1/test?a=b&a=c');
it("list-like query parameters", () => {
const result = route("/test", { a: ["b", "c"] });
expect(result).toBe("/api/v1/test?a=b&a=c");
});
});

View file

@ -1,2 +1,2 @@
export { BaseAPI } from './base-api';
export { route } from './urls';
export { BaseAPI } from "./base-api";
export { route } from "./urls";

View file

@ -1,6 +1,6 @@
const parts = {
host: 'http://localhost.com',
prefix: '/api/v1',
host: "http://localhost.com",
prefix: "/api/v1",
};
export function overrideParts(host: string, prefix: string) {
@ -32,5 +32,5 @@ export function route(rest: string, params: Record<string, QueryValue> = {}): st
}
}
return url.toString().replace('http://localhost.com', '');
return url.toString().replace("http://localhost.com", "");
}

View file

@ -1,7 +1,7 @@
import { BaseAPI, route } from '../base';
import { Label } from './labels';
import { Location } from './locations';
import { Results } from './types';
import { BaseAPI, route } from "../base";
import { Label } from "./labels";
import { Location } from "./locations";
import { Results } from "./types";
export interface ItemCreate {
name: string;
@ -35,12 +35,12 @@ export interface Item {
}
export class ItemsApi extends BaseAPI {
async getAll() {
return this.http.get<Results<Item>>({ url: route('/items') });
getAll() {
return this.http.get<Results<Item>>({ url: route("/items") });
}
async create(item: ItemCreate) {
return this.http.post<ItemCreate, Item>({ url: route('/items'), body: item });
create(item: ItemCreate) {
return this.http.post<ItemCreate, Item>({ url: route("/items"), body: item });
}
async get(id: string) {
@ -58,18 +58,18 @@ export class ItemsApi extends BaseAPI {
return payload;
}
async delete(id: string) {
delete(id: string) {
return this.http.delete<void>({ url: route(`/items/${id}`) });
}
async update(id: string, item: ItemCreate) {
update(id: string, item: ItemCreate) {
return this.http.put<ItemCreate, Item>({ url: route(`/items/${id}`), body: item });
}
async import(file: File) {
import(file: File) {
const formData = new FormData();
formData.append('csv', file);
formData.append("csv", file);
return this.http.post<FormData, void>({ url: route('/items/import'), data: formData });
return this.http.post<FormData, void>({ url: route("/items/import"), data: formData });
}
}

View file

@ -1,6 +1,6 @@
import { BaseAPI, route } from '../base';
import { Item } from './items';
import { Details, OutType, Results } from './types';
import { BaseAPI, route } from "../base";
import { Item } from "./items";
import { Details, OutType, Results } from "./types";
export type LabelCreate = Details & {
color: string;
@ -15,23 +15,23 @@ export type Label = LabelCreate &
};
export class LabelsApi extends BaseAPI {
async getAll() {
return this.http.get<Results<Label>>({ url: route('/labels') });
getAll() {
return this.http.get<Results<Label>>({ url: route("/labels") });
}
async create(body: LabelCreate) {
return this.http.post<LabelCreate, Label>({ url: route('/labels'), body });
create(body: LabelCreate) {
return this.http.post<LabelCreate, Label>({ url: route("/labels"), body });
}
async get(id: string) {
get(id: string) {
return this.http.get<Label>({ url: route(`/labels/${id}`) });
}
async delete(id: string) {
delete(id: string) {
return this.http.delete<void>({ url: route(`/labels/${id}`) });
}
async update(id: string, body: LabelUpdate) {
update(id: string, body: LabelUpdate) {
return this.http.put<LabelUpdate, Label>({ url: route(`/labels/${id}`), body });
}
}

View file

@ -1,6 +1,6 @@
import { BaseAPI, route } from '../base';
import { Item } from './items';
import { Details, OutType, Results } from './types';
import { BaseAPI, route } from "../base";
import { Item } from "./items";
import { Details, OutType, Results } from "./types";
export type LocationCreate = Details;
@ -14,22 +14,23 @@ export type Location = LocationCreate &
export type LocationUpdate = LocationCreate;
export class LocationsApi extends BaseAPI {
async getAll() {
return this.http.get<Results<Location>>({ url: route('/locations') });
getAll() {
return this.http.get<Results<Location>>({ url: route("/locations") });
}
async create(body: LocationCreate) {
return this.http.post<LocationCreate, Location>({ url: route('/locations'), body });
create(body: LocationCreate) {
return this.http.post<LocationCreate, Location>({ url: route("/locations"), body });
}
async get(id: string) {
get(id: string) {
return this.http.get<Location>({ url: route(`/locations/${id}`) });
}
async delete(id: string) {
delete(id: string) {
return this.http.delete<void>({ url: route(`/locations/${id}`) });
}
async update(id: string, body: LocationUpdate) {
update(id: string, body: LocationUpdate) {
return this.http.put<LocationUpdate, Location>({ url: route(`/locations/${id}`), body });
}
}

View file

@ -1,4 +1,4 @@
import { BaseAPI, route } from './base';
import { BaseAPI, route } from "./base";
export type LoginResult = {
token: string;
@ -28,12 +28,12 @@ export type StatusResult = {
export class PublicApi extends BaseAPI {
public status() {
return this.http.get<StatusResult>({ url: route('/status') });
return this.http.get<StatusResult>({ url: route("/status") });
}
public login(username: string, password: string) {
return this.http.post<LoginPayload, LoginResult>({
url: route('/users/login'),
url: route("/users/login"),
body: {
username,
password,
@ -42,6 +42,6 @@ export class PublicApi extends BaseAPI {
}
public register(body: RegisterPayload) {
return this.http.post<RegisterPayload, LoginResult>({ url: route('/users/register'), body });
return this.http.post<RegisterPayload, LoginResult>({ url: route("/users/register"), body });
}
}

View file

@ -1,8 +1,8 @@
import { Requests } from '~~/lib/requests';
import { BaseAPI, route } from './base';
import { ItemsApi } from './classes/items';
import { LabelsApi } from './classes/labels';
import { LocationsApi } from './classes/locations';
import { BaseAPI, route } from "./base";
import { ItemsApi } from "./classes/items";
import { LabelsApi } from "./classes/labels";
import { LocationsApi } from "./classes/locations";
import { Requests } from "~~/lib/requests";
export type Result<T> = {
item: T;
@ -30,14 +30,14 @@ export class UserApi extends BaseAPI {
}
public self() {
return this.http.get<Result<User>>({ url: route('/users/self') });
return this.http.get<Result<User>>({ url: route("/users/self") });
}
public logout() {
return this.http.post<object, void>({ url: route('/users/logout') });
return this.http.post<object, void>({ url: route("/users/logout") });
}
public deleteAccount() {
return this.http.delete<void>({ url: route('/users/self') });
return this.http.delete<void>({ url: route("/users/self") });
}
}