Skip to content

Commit

Permalink
Fix naming conventions, tests + config, proper jest-when checks
Browse files Browse the repository at this point in the history
  • Loading branch information
hrax committed Aug 11, 2024
1 parent c237c16 commit fc64da2
Show file tree
Hide file tree
Showing 22 changed files with 304 additions and 387 deletions.
6 changes: 5 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,18 @@ const config: JestConfigWithTsJest = {
// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// onlyFailures: true,

// A preset that is used as a base for Jest's configuration
// preset: undefined,

// Run tests from one or more projects
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
// reporters: [
// "summary"
// ],

// Automatically reset mock state before every test
// resetMocks: false,
Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@babel/core": "^7.25.2",
"@babel/eslint-parser": "^7.25.1",
"@jest/globals": "^29.7.0",
"@types/eslint": "^9.6.0",
"@types/jest": "^29.5.12",
"@types/jest-when": "^3.5.5",
"@types/node": "^22.0.0",
Expand Down
14 changes: 7 additions & 7 deletions src/core/OAuthClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { URL, URLSearchParams } from "url";
import { Request, Response } from "./Request.js";
import { RequestOptions } from "https";
import { Package } from "./Package.js";
import { SNOAuthToken } from "./sn.js";
import { SNOAuthTokenData } from "./sn.js";
import { InstanceAuthenticationData, InstanceConfig, InstanceOAuthTokenData, Profile, ProfileManager } from "./ProfileManager.js";

const CLIENT_BASE_URL: string = "/oauth_entity.do";
Expand Down Expand Up @@ -94,7 +94,7 @@ export class OAuthClient {
return url;
}

async requestTokenByCode(profile: Profile, code: string): Promise<SNOAuthToken> {
async requestTokenByCode(profile: Profile, code: string): Promise<SNOAuthTokenData> {
const url: URL = new URL(TOKEN_BASE_URL, profile.getBaseUrl());

const body: URLSearchParams = new URLSearchParams();
Expand All @@ -112,7 +112,7 @@ export class OAuthClient {
}
};

const token: SNOAuthToken = await Request.json(url, options, body.toString())
const token: SNOAuthTokenData = await Request.json(url, options, body.toString())
.catch((reason: any) => {
if (reason instanceof Response) {
const response: Response = reason;
Expand All @@ -127,7 +127,7 @@ export class OAuthClient {
return token;
}

async requestTokenByUsername(profile: Profile, username: string, password: string): Promise<SNOAuthToken> {
async requestTokenByUsername(profile: Profile, username: string, password: string): Promise<SNOAuthTokenData> {
const url: URL = new URL(TOKEN_BASE_URL, profile.getBaseUrl());

const body: URLSearchParams = new URLSearchParams();
Expand All @@ -145,7 +145,7 @@ export class OAuthClient {
}
};

const token: SNOAuthToken = await Request.json(url, options, body.toString())
const token: SNOAuthTokenData = await Request.json(url, options, body.toString())
.catch((reason: any) => {
if (reason instanceof Response) {
const response: Response = reason;
Expand All @@ -160,7 +160,7 @@ export class OAuthClient {
return token;
}

async refreshToken(profile: Profile): Promise<SNOAuthToken> {
async refreshToken(profile: Profile): Promise<SNOAuthTokenData> {
const url: URL = new URL(TOKEN_BASE_URL, profile.getBaseUrl());

const body: URLSearchParams = new URLSearchParams();
Expand All @@ -177,7 +177,7 @@ export class OAuthClient {
}
};

const token: SNOAuthToken = await Request.json(url, options, body.toString())
const token: SNOAuthTokenData = await Request.json(url, options, body.toString())
.catch((reason: any) => {
if (reason instanceof Response) {
const response: Response = reason;
Expand Down
8 changes: 4 additions & 4 deletions src/core/ProfileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os from "os";
import path from "path";

import { RESTClient } from "./RESTClient.js";
import { SNOAuthToken, SNTable } from "./sn.js";
import { SNOAuthTokenData, SNTable } from "./sn.js";

class Constants {
static readonly PROFILES_FOLDER_NAME = ".now-eslint-profiles";
Expand Down Expand Up @@ -145,11 +145,11 @@ export class Profile {
return this.config.auth;
}

getToken(): SNOAuthToken | null | undefined {
getToken(): SNOAuthTokenData | null | undefined {
return this.config.auth.token;
}

refreshToken(token: SNOAuthToken) {
refreshToken(token: SNOAuthTokenData) {
this.config.auth.lastRetrieved = Date.now();
this.config.auth.token = token;
}
Expand Down Expand Up @@ -178,7 +178,7 @@ export interface InstanceOAuthTokenData {
clientID: string;
clientSecret: string;
lastRetrieved: number;
token?: SNOAuthToken | null;
token?: SNOAuthTokenData | null;
}

export interface InstanceUserData {
Expand Down
23 changes: 3 additions & 20 deletions src/core/RESTClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { OAuthClient } from "./OAuthClient.js";
import { Request, Response } from "./Request.js";
import { Package } from "./Package.js";
import { InstanceConfig, Profile, TableConfig } from "./ProfileManager.js";
import { SNUpdateXMLData } from "./sn.js";

export class RESPONSE_STATUS {
static readonly OK = 200 as const;
Expand Down Expand Up @@ -227,7 +228,7 @@ export class RESTClient {
return pref;
}

async loadUpdateXMLByUpdateSetIds(profile: Profile, ...ids: string[]): Promise<any> {
async loadUpdateXMLByUpdateSetIds(profile: Profile, ...ids: string[]): Promise<Array<SNUpdateXMLData>> {
if (ids.length === 0) {
ids.push("-1");
}
Expand All @@ -249,9 +250,7 @@ export class RESTClient {

await this.oauthClient.handleAuthentication(profile, options);

const response: JSONRESTResponse<UpdateXMLData> = await Request.json(url, options);


return (<JSONRESTResponse<SNUpdateXMLData>> await Request.json(url, options)).result;
}

async loadUpdateXMLByUpdateSetQuery(profile: Profile, ids: string): Promise<any> {
Expand All @@ -269,22 +268,6 @@ export interface TableParentData {
"super_class.name": string;
}

export interface UpdateXMLData {
sys_id: string;
name: string;
action: string;
type: "INSERT_OR_UPDATE" | "DELETE";
target_name: string;
update_set: string;

sys_created_on: string;
sys_created_by: string;
sys_updated_on: string;
sys_updated_by: string;
payload: string;

}

export interface JSONRESTResponse<T = any> {
result: Array<T>
}
Empty file removed src/core/UpdateXML.ts
Empty file.
Loading

0 comments on commit fc64da2

Please sign in to comment.