Skip to content

Commit

Permalink
feat: added validation and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
The24thDS committed Jan 18, 2024
1 parent 1186a8f commit e4fe494
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
EMAIL=some@mail.dom
PASSWORD=thepaswsord
EMAIL="some@mail.dom"
PASSWORD="thepaswsord"
MOD_ID="111"
31 changes: 23 additions & 8 deletions index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import 'dotenv/config';
import { test, expect } from '@playwright/test';
import path from 'path';
import fs from 'fs';
import invariant from 'tiny-invariant';
import { test, expect } from '@playwright/test';

import { getGameVersionFromDescriptor, getModVersionFromDescriptor } from './utils';

invariant(process.env.EMAIL, 'You must provide an EMAIL');
invariant(process.env.PASSWORD, 'You must provide a PASSWORD');

const MOD_FOLDER_PATH = path.join(__dirname, process.env.MOD_FOLDER_PATH || 'mod');
const MOD_DESCRIPTOR_PATH = path.join(MOD_FOLDER_PATH, 'descriptor.mod');
invariant(fs.existsSync(MOD_DESCRIPTOR_PATH), `You must provide a descriptor.mod file in ${MOD_FOLDER_PATH}`);
const MOD_ARCHIVE_PATH = process.env.MOD_ARCHIVE_PATH ? path.join(__dirname, process.env.MOD_ARCHIVE_PATH) : path.join(MOD_FOLDER_PATH, 'mod.zip');
invariant(fs.existsSync(MOD_ARCHIVE_PATH), `You must provide a mod archive in ${MOD_FOLDER_PATH}`);

const MOD_ID = process.env.MOD_ID;
invariant(MOD_ID, 'You must provide a MOD_ID');

const MOD_ID = '72663';
const MOD_VERSION = '1.0.3';
const GAME_VERSION = '3.10.1';
const UPLOAD_TIMEOUT = 60_000 * 20;
const RELEASE_NOTES = 'fix bug 3';
const MOD_VERSION = process.env.MOD_VERSION ?? getModVersionFromDescriptor(MOD_DESCRIPTOR_PATH);
const GAME_VERSION = process.env.GAME_VERSION ?? getGameVersionFromDescriptor(MOD_DESCRIPTOR_PATH);
const UPLOAD_TIMEOUT = Number(process.env.UPLOAD_TIMEOUT) ?? 60_000 * 20;
const RELEASE_NOTES = process.env.RELEASE_NOTES || 'No release notes provided.';

test('test', async ({ page }) => {
test('Upload mod', async ({ page }) => {
// Step 1. Login
await page.goto(
'https://login.paradoxplaza.com/login?service=https%3A%2F%2Fmods.paradoxplaza.com%2Fvalidate%3Fredirect%3D%252F'
Expand Down Expand Up @@ -39,7 +54,7 @@ test('test', async ({ page }) => {
const fileChooserPromise = page.waitForEvent('filechooser');
await page.getByLabel('files').locator('div[role="button"]').click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(path.join(__dirname, 'Archive.zip'));
await fileChooser.setFiles(MOD_ARCHIVE_PATH);
await expect(
page.getByLabel('files').locator('[class*=__loader]')
).not.toHaveClass(/__active/, { timeout: UPLOAD_TIMEOUT });
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@playwright/test": "^1.41.0",
"@types/node": "^20.11.4"
},
"scripts": {},
"scripts": {
"start": "playwright test"
},
"dependencies": {
"dotenv": "^16.3.1"
"@playwright/test": "^1.41.0",
"dotenv": "^16.3.1",
"tiny-invariant": "^1.3.1"
}
}
24 changes: 24 additions & 0 deletions utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { PathLike } from "fs";
import fs from 'fs';

/**
* Accepts a path to a mod descriptor and returns the value of the `version` keyword found in that file.
*/
export const getModVersionFromDescriptor = (path: PathLike) => {
const data = fs.readFileSync(path, 'utf8');
const versionLine = data.split('\n').find(line => line.startsWith('version='));
if (!versionLine) throw new Error('Version not found in descriptor');
const version = versionLine.split('=')[1].replace(/"/g, '');
return version;
}

/**
* Accepts a path to a mod descriptor and returns the value of the `supported_version` keyword found in that file.
*/
export const getGameVersionFromDescriptor = (path: PathLike) => {
const data = fs.readFileSync(path, 'utf8');
const versionLine = data.split('\n').find(line => line.startsWith('supported_version='));
if (!versionLine) throw new Error('Game version not found in descriptor');
const version = versionLine.split('=')[1].replace(/"/g, '');
return version;
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ playwright@1.41.0:
optionalDependencies:
fsevents "2.3.2"

tiny-invariant@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.3.1.tgz#8560808c916ef02ecfd55e66090df23a4b7aa642"
integrity sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw==

undici-types@~5.26.4:
version "5.26.5"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
Expand Down

0 comments on commit e4fe494

Please sign in to comment.