mirror of
https://github.com/barthuijgen/factorio-sites.git
synced 2025-02-12 14:56:00 +02:00
Fix jest warnings and apply lint and test in github actions to all apps and libs
This commit is contained in:
parent
033477221e
commit
5db0d221d3
4
.github/workflows/validate.yml
vendored
4
.github/workflows/validate.yml
vendored
@ -22,6 +22,6 @@ jobs:
|
||||
${{ runner.os }}-yarn-
|
||||
- run: yarn --prefer-offline
|
||||
- run: yarn db-gen
|
||||
- run: yarn nx lint
|
||||
- run: yarn nx test
|
||||
- run: nx run-many --all --target=lint
|
||||
- run: nx run-many --all --target=test "--ci"
|
||||
- run: yarn nx build blueprints
|
||||
|
@ -3,7 +3,7 @@ module.exports = {
|
||||
preset: "../../jest.preset.js",
|
||||
globals: {
|
||||
"ts-jest": {
|
||||
tsConfig: "<rootDir>/tsconfig.spec.json",
|
||||
tsconfig: "<rootDir>/tsconfig.spec.json",
|
||||
},
|
||||
},
|
||||
transform: {
|
||||
|
@ -24,6 +24,7 @@ interface Res {
|
||||
send(body: string): void;
|
||||
}
|
||||
/** message body for pubsub triggered function */
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type Message = Record<string, any>;
|
||||
/** context for pubsub triggered function */
|
||||
interface Context {
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { timeLogger } from "@factorio-sites/common-utils";
|
||||
import * as Puppeteer from "puppeteer";
|
||||
|
||||
|
@ -3,7 +3,7 @@ module.exports = {
|
||||
preset: "../../jest.preset.js",
|
||||
globals: {
|
||||
"ts-jest": {
|
||||
tsConfig: "<rootDir>/tsconfig.spec.json",
|
||||
tsconfig: "<rootDir>/tsconfig.spec.json",
|
||||
},
|
||||
},
|
||||
transform: {
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import * as crypto from "crypto";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
@ -3,7 +3,7 @@ module.exports = {
|
||||
preset: "../../jest.preset.js",
|
||||
globals: {
|
||||
"ts-jest": {
|
||||
tsConfig: "<rootDir>/tsconfig.spec.json",
|
||||
tsconfig: "<rootDir>/tsconfig.spec.json",
|
||||
},
|
||||
},
|
||||
transform: {
|
||||
|
@ -4,7 +4,7 @@ module.exports = {
|
||||
preset: "../../jest.preset.js",
|
||||
globals: {
|
||||
"ts-jest": {
|
||||
tsConfig: "<rootDir>/tsconfig.spec.json",
|
||||
tsconfig: "<rootDir>/tsconfig.spec.json",
|
||||
},
|
||||
},
|
||||
transform: {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { BlueprintBookData } from "@factorio-sites/types";
|
||||
import { encodeBlueprint, hashString } from "@factorio-sites/node-utils";
|
||||
import { blueprint_book } from "@prisma/client";
|
||||
import { blueprint_book, Prisma } from "@prisma/client";
|
||||
import { saveBlueprintString } from "../gcp-storage";
|
||||
import { prisma } from "../postgres/database";
|
||||
import { BlueprintBook, ChildTree } from "@factorio-sites/types";
|
||||
@ -8,7 +8,7 @@ import { createBlueprint } from "./blueprint";
|
||||
|
||||
const mapBlueprintBookEntityToObject = (entity: blueprint_book): BlueprintBook => ({
|
||||
id: entity.id,
|
||||
child_tree: entity.child_tree ? (entity.child_tree as any) : [],
|
||||
child_tree: entity.child_tree ? ((entity.child_tree as unknown) as ChildTree) : [],
|
||||
blueprint_hash: entity.blueprint_hash,
|
||||
label: entity.label || "",
|
||||
description: entity.description || "",
|
||||
@ -81,7 +81,7 @@ export async function createBlueprintBook(
|
||||
description: blueprintBook.description,
|
||||
blueprint_hash: blueprint_hash,
|
||||
is_modded: false,
|
||||
child_tree: child_tree as any,
|
||||
child_tree: (child_tree as unknown) as Prisma.InputJsonObject,
|
||||
updated_at: extraInfo.updated_at ? new Date(extraInfo.updated_at * 1000) : new Date(),
|
||||
created_at: extraInfo.created_at ? new Date(extraInfo.created_at * 1000) : new Date(),
|
||||
blueprint_books: {
|
||||
|
@ -22,7 +22,8 @@ const mapBlueprintPageEntityToObject = (
|
||||
created_at: entity.created_at && entity.created_at.getTime() / 1000,
|
||||
updated_at: entity.updated_at && entity.updated_at.getTime() / 1000,
|
||||
factorioprints_id: entity.factorioprints_id ?? null,
|
||||
favorite_count: (entity as any).favorite_count || null,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
favorite_count: (entity as any).favorite_count || (entity as any).user_favorites?.length || 0,
|
||||
user: user ? { id: user.id, username: user.username } : null,
|
||||
});
|
||||
|
||||
@ -37,7 +38,12 @@ export async function getBlueprintPageByUserId(user_id: string): Promise<Bluepri
|
||||
}
|
||||
|
||||
export async function getBlueprintPageWithUserById(id: string): Promise<BlueprintPage | null> {
|
||||
const result = await prisma.blueprint_page.findUnique({ where: { id }, include: { user: true } });
|
||||
// TODO: the user_favorites join is inefficient because it's only for counting
|
||||
// https://github.com/prisma/prisma/issues/5079
|
||||
const result = await prisma.blueprint_page.findUnique({
|
||||
where: { id },
|
||||
include: { user: true, user_favorites: true },
|
||||
});
|
||||
return result ? mapBlueprintPageEntityToObject(result, result.user) : null;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ module.exports = {
|
||||
preset: "../../jest.preset.js",
|
||||
globals: {
|
||||
"ts-jest": {
|
||||
tsConfig: "<rootDir>/tsconfig.spec.json",
|
||||
tsconfig: "<rootDir>/tsconfig.spec.json",
|
||||
},
|
||||
},
|
||||
transform: {
|
||||
|
@ -3,7 +3,7 @@ module.exports = {
|
||||
preset: "../../jest.preset.js",
|
||||
globals: {
|
||||
"ts-jest": {
|
||||
tsConfig: "<rootDir>/tsconfig.spec.json",
|
||||
tsconfig: "<rootDir>/tsconfig.spec.json",
|
||||
},
|
||||
},
|
||||
transform: {
|
||||
|
@ -52,7 +52,7 @@ export interface BlueprintPage {
|
||||
created_at: number;
|
||||
updated_at: number;
|
||||
factorioprints_id: string | null;
|
||||
favorite_count?: number;
|
||||
favorite_count: number;
|
||||
user: { id: string; username: string } | null;
|
||||
// BlueprintPageEntry->BlueprintEntry 1:m
|
||||
// BlueprintPageEntry->BlueprintBook 1:m
|
||||
|
@ -3,7 +3,7 @@ module.exports = {
|
||||
preset: "../../jest.preset.js",
|
||||
globals: {
|
||||
"ts-jest": {
|
||||
tsConfig: "<rootDir>/tsconfig.spec.json",
|
||||
tsconfig: "<rootDir>/tsconfig.spec.json",
|
||||
},
|
||||
},
|
||||
transform: {
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
export const Base64 = {
|
||||
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
||||
encode: function (input: any) {
|
||||
@ -57,7 +58,7 @@ export const Base64 = {
|
||||
let chr1, chr2, chr3;
|
||||
let enc1, enc2, enc3, enc4;
|
||||
let i = 0;
|
||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||
input = input.replace(/[^A-Za-z0-9+/=]/g, "");
|
||||
while (i < input.length) {
|
||||
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
||||
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
||||
|
11
libs/web-utils/src/lib/web-utils.spec.ts
Normal file
11
libs/web-utils/src/lib/web-utils.spec.ts
Normal file
@ -0,0 +1,11 @@
|
||||
// import { parseBlueprintStringClient } from "./web-utils";
|
||||
|
||||
// const EXAMPLE_STRING =
|
||||
// "0eNptjsEOgkAQQ/+l54UILKL7K8YYwIlOAgNhByMh+++yePHgsU372hVNN9M4sSjcCm4H8XCXFZ4fUnfR02UkOLBSDwOp+6i8EnVJ+ySvCAYsd3rDZeFqQKKsTF/MLpabzH1D0xb4CzAYB791Bol7Gycp0tJggTse0jJE6L7ufs4avGjyeyU/ZbY651VhbWVzG8IHG4NFbQ==";
|
||||
|
||||
describe("utils", () => {
|
||||
it("should work", () => {
|
||||
// TextEncoder does not work in jest
|
||||
expect(1).toBe(1);
|
||||
});
|
||||
});
|
@ -28,7 +28,7 @@ export function encodeBlueprintClient(data: BlueprintStringData): string {
|
||||
const string = JSON.stringify(data);
|
||||
const encoded = new TextEncoder().encode(string);
|
||||
const compresed = pako.deflate(encoded, { level: 9 });
|
||||
return "0" + Base64.encodeU(compresed as any);
|
||||
return "0" + Base64.encodeU(compresed);
|
||||
}
|
||||
|
||||
export function getFirstBookFromString(string: string): BlueprintString | null {
|
||||
@ -38,6 +38,7 @@ export function getFirstBookFromString(string: string): BlueprintString | null {
|
||||
else if (data.blueprint_book) {
|
||||
const bpData = data.blueprint_book.blueprints.find((bp) => !!bp.blueprint);
|
||||
if (bpData) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { index, ...bp } = bpData;
|
||||
return bp as BlueprintString;
|
||||
}
|
||||
@ -87,6 +88,7 @@ export function mergeBlueprintDataAndChildTree(
|
||||
parent: child_tree_item,
|
||||
bp_data: data.blueprint_book,
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return { ...child, icons: [] } as any;
|
||||
}
|
||||
}),
|
||||
|
Loading…
x
Reference in New Issue
Block a user