1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-16 00:20:06 +00:00

feat(*): recreate package with new name

This commit is contained in:
Krishna Acondy
2020-07-07 19:53:35 +01:00
commit 066f953863
150 changed files with 48625 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
import SASjs, { ServerType, SASjsConfig } from "sasjs";
import { TestSuite } from "../types";
const defaultConfig: SASjsConfig = {
serverUrl: window.location.origin,
pathSAS9: "/SASStoredProcess/do",
pathSASViya: "/SASJobExecution",
appLoc: "/Public/seedapp",
serverType: ServerType.SASViya,
debug: true,
contextName: "SAS Job Execution compute context",
};
const customConfig = {
serverUrl: "url",
pathSAS9: "sas9",
pathSASViya: "viya",
appLoc: "/Public/seedapp",
serverType: ServerType.SAS9,
debug: false,
};
export const basicTests = (
adapter: SASjs,
userName: string,
password: string
): TestSuite => ({
name: "Basic Tests",
tests: [
{
title: "Log in",
description: "Should log the user in",
test: async () => {
return adapter.logIn(userName, password);
},
assertion: (response: any) =>
response && response.isLoggedIn && response.userName === userName,
},
{
title: "Default config",
description:
"Should instantiate with default config when none is provided",
test: async () => {
return Promise.resolve(new SASjs());
},
assertion: (sasjsInstance: SASjs) => {
const sasjsConfig = sasjsInstance.getSasjsConfig();
return (
sasjsConfig.serverUrl === defaultConfig.serverUrl &&
sasjsConfig.pathSAS9 === defaultConfig.pathSAS9 &&
sasjsConfig.pathSASViya === defaultConfig.pathSASViya &&
sasjsConfig.appLoc === defaultConfig.appLoc &&
sasjsConfig.serverType === defaultConfig.serverType &&
sasjsConfig.debug === defaultConfig.debug
);
},
},
{
title: "Custom config",
description: "Should use fully custom config whenever supplied",
test: async () => {
return Promise.resolve(new SASjs(customConfig));
},
assertion: (sasjsInstance: SASjs) => {
const sasjsConfig = sasjsInstance.getSasjsConfig();
return (
sasjsConfig.serverUrl === customConfig.serverUrl &&
sasjsConfig.pathSAS9 === customConfig.pathSAS9 &&
sasjsConfig.pathSASViya === customConfig.pathSASViya &&
sasjsConfig.appLoc === customConfig.appLoc &&
sasjsConfig.serverType === customConfig.serverType &&
sasjsConfig.debug === customConfig.debug
);
},
},
{
title: "Config overrides",
description: "Should override default config with supplied properties",
test: async () => {
return Promise.resolve(
new SASjs({ serverUrl: "http://test.com", debug: false })
);
},
assertion: (sasjsInstance: SASjs) => {
const sasjsConfig = sasjsInstance.getSasjsConfig();
return (
sasjsConfig.serverUrl === "http://test.com" &&
sasjsConfig.pathSAS9 === defaultConfig.pathSAS9 &&
sasjsConfig.pathSASViya === defaultConfig.pathSASViya &&
sasjsConfig.appLoc === defaultConfig.appLoc &&
sasjsConfig.serverType === defaultConfig.serverType &&
sasjsConfig.debug === false
);
},
},
],
});

View File

@@ -0,0 +1,308 @@
import SASjs from "sasjs";
import { TestSuite } from "../types";
const stringData: any = { table1: [{ col1: "first col value" }] };
const numericData: any = { table1: [{ col1: 3.14159265 }] };
const multiColumnData: any = {
table1: [{ col1: 42, col2: 1.618, col3: "x", col4: "x" }],
};
const multipleRowsWithNulls: any = {
table1: [
{ col1: 42, col2: null, col3: "x", col4: "" },
{ col1: 42, col2: null, col3: "x", col4: "" },
{ col1: 42, col2: null, col3: "x", col4: "" },
{ col1: 42, col2: 1.62, col3: "x", col4: "x" },
{ col1: 42, col2: 1.62, col3: "x", col4: "x" },
],
};
const multipleColumnsWithNulls: any = {
table1: [
{ col1: 42, col2: null, col3: "x", col4: null },
{ col1: 42, col2: null, col3: "x", col4: null },
{ col1: 42, col2: null, col3: "x", col4: null },
{ col1: 42, col2: null, col3: "x", col4: "" },
{ col1: 42, col2: null, col3: "x", col4: "" },
],
};
const getLongStringData = (length = 32764) => {
let x = "X";
for (let i = 1; i <= length; i++) {
x = x + "X";
}
const data: any = { table1: [{ col1: x }] };
return data;
};
const getLargeObjectData = () => {
const data = { table1: [{ big: "data" }] };
for (let i = 1; i < 10000; i++) {
data.table1.push(data.table1[0]);
}
return data;
};
export const sendArrTests = (adapter: SASjs): TestSuite => ({
name: "sendArr",
tests: [
{
title: "Single string value",
description: "Should send an array with a single string value",
test: () => {
return adapter.request("common/sendArr", stringData);
},
assertion: (res: any) => {
return res.table1[0][0] === stringData.table1[0].col1;
},
},
{
title: "Long string value",
description:
"Should send an array with a long string value under 32765 characters",
test: () => {
return adapter.request("common/sendArr", getLongStringData());
},
assertion: (res: any) => {
const longStringData = getLongStringData();
return res.table1[0][0] === longStringData.table1[0].col1;
},
},
{
title: "Overly long string value",
description:
"Should error out with long string values over 32765 characters",
test: () => {
return adapter
.request("common/sendArr", getLongStringData(32767))
.catch((e) => e);
},
assertion: (error: any) => {
return !!error && !!error.MESSAGE;
},
},
{
title: "Single numeric value",
description: "Should send an array with a single numeric value",
test: () => {
return adapter.request("common/sendArr", numericData);
},
assertion: (res: any) => {
return res.table1[0][0] === numericData.table1[0].col1;
},
},
{
title: "Multiple columns",
description: "Should handle data with multiple columns",
test: () => {
return adapter.request("common/sendArr", multiColumnData);
},
assertion: (res: any) => {
return (
res.table1[0][0] === multiColumnData.table1[0].col1 &&
res.table1[0][1] === multiColumnData.table1[0].col2 &&
res.table1[0][2] === multiColumnData.table1[0].col3 &&
res.table1[0][3] === multiColumnData.table1[0].col4
);
},
},
{
title: "Multiple rows with nulls",
description: "Should handle data with multiple rows with null values",
test: () => {
return adapter.request("common/sendArr", multipleRowsWithNulls);
},
assertion: (res: any) => {
let result = true;
multipleRowsWithNulls.table1.forEach((_: any, index: number) => {
result =
result &&
res.table1[index][0] === multipleRowsWithNulls.table1[index].col1;
result =
result &&
res.table1[index][1] === multipleRowsWithNulls.table1[index].col2;
result =
result &&
res.table1[index][2] === multipleRowsWithNulls.table1[index].col3;
result =
result &&
res.table1[index][3] === multipleRowsWithNulls.table1[index].col4;
});
return result;
},
},
{
title: "Multiple columns with nulls",
description: "Should handle data with multiple columns with null values",
test: () => {
return adapter.request("common/sendArr", multipleColumnsWithNulls);
},
assertion: (res: any) => {
let result = true;
multipleColumnsWithNulls.table1.forEach((_: any, index: number) => {
result =
result &&
res.table1[index][0] ===
multipleColumnsWithNulls.table1[index].col1;
result =
result &&
res.table1[index][1] ===
multipleColumnsWithNulls.table1[index].col2;
result =
result &&
res.table1[index][2] ===
multipleColumnsWithNulls.table1[index].col3;
result =
result &&
res.table1[index][3] ===
(multipleColumnsWithNulls.table1[index].col4 || "");
});
return result;
},
},
],
});
export const sendObjTests = (adapter: SASjs): TestSuite => ({
name: "sendObj",
tests: [
{
title: "Invalid column name",
description: "Should throw an error",
test: async () => {
const invalidData: any = {
"1 invalid table": [{ col1: 42 }],
};
return adapter.request("common/sendObj", invalidData).catch((e) => e);
},
assertion: (error: any) => !!error && !!error.MESSAGE,
},
{
title: "Single string value",
description: "Should send an object with a single string value",
test: () => {
return adapter.request("common/sendObj", stringData);
},
assertion: (res: any) => {
return res.table1[0].COL1 === stringData.table1[0].col1;
},
},
{
title: "Long string value",
description:
"Should send an object with a long string value under 32765 characters",
test: () => {
return adapter.request("common/sendObj", getLongStringData());
},
assertion: (res: any) => {
const longStringData = getLongStringData();
return res.table1[0].COL1 === longStringData.table1[0].col1;
},
},
{
title: "Overly long string value",
description:
"Should error out with long string values over 32765 characters",
test: () => {
return adapter
.request("common/sendObj", getLongStringData(32767))
.catch((e) => e);
},
assertion: (error: any) => {
return !!error && !!error.MESSAGE;
},
},
{
title: "Single numeric value",
description: "Should send an object with a single numeric value",
test: () => {
return adapter.request("common/sendObj", numericData);
},
assertion: (res: any) => {
return res.table1[0].COL1 === numericData.table1[0].col1;
},
},
{
title: "Large data volume",
description: "Should send an object with a large amount of data",
test: () => {
return adapter.request("common/sendObj", getLargeObjectData());
},
assertion: (res: any) => {
const data = getLargeObjectData();
return res.table1[9000].BIG === data.table1[9000].big;
},
},
{
title: "Multiple columns",
description: "Should handle data with multiple columns",
test: () => {
return adapter.request("common/sendObj", multiColumnData);
},
assertion: (res: any) => {
return (
res.table1[0].COL1 === multiColumnData.table1[0].col1 &&
res.table1[0].COL2 === multiColumnData.table1[0].col2 &&
res.table1[0].COL3 === multiColumnData.table1[0].col3 &&
res.table1[0].COL4 === multiColumnData.table1[0].col4
);
},
},
{
title: "Multiple rows with nulls",
description: "Should handle data with multiple rows with null values",
test: () => {
return adapter.request("common/sendObj", multipleRowsWithNulls);
},
assertion: (res: any) => {
let result = true;
multipleRowsWithNulls.table1.forEach((_: any, index: number) => {
result =
result &&
res.table1[index].COL1 === multipleRowsWithNulls.table1[index].col1;
result =
result &&
res.table1[index].COL2 === multipleRowsWithNulls.table1[index].col2;
result =
result &&
res.table1[index].COL3 === multipleRowsWithNulls.table1[index].col3;
result =
result &&
res.table1[index].COL4 === multipleRowsWithNulls.table1[index].col4;
});
return result;
},
},
{
title: "Multiple columns with nulls",
description: "Should handle data with multiple columns with null values",
test: () => {
return adapter.request("common/sendObj", multipleColumnsWithNulls);
},
assertion: (res: any) => {
let result = true;
multipleColumnsWithNulls.table1.forEach((_: any, index: number) => {
result =
result &&
res.table1[index].COL1 ===
multipleColumnsWithNulls.table1[index].col1;
result =
result &&
res.table1[index].COL2 ===
multipleColumnsWithNulls.table1[index].col2;
result =
result &&
res.table1[index].COL3 ===
multipleColumnsWithNulls.table1[index].col3;
result =
result &&
res.table1[index].COL4 ===
(multipleColumnsWithNulls.table1[index].col4 || "");
});
return result;
},
},
],
});

View File

@@ -0,0 +1,25 @@
import SASjs from "sasjs";
import { TestSuite } from "../types";
const data: any = { table1: [{ col1: "first col value" }] };
export const sasjsRequestTests = (adapter: SASjs): TestSuite => ({
name: "SASjs Requests",
tests: [
{
title: "WORK tables",
description: "Should get WORK tables after request",
test: async () => {
return adapter.request("common/sendArr", data);
},
assertion: (res: any) => {
const requests = adapter.getSasRequests();
if (adapter.getSasjsConfig().debug) {
return requests[0].SASWORK !== null;
} else {
return requests[0].SASWORK === null;
}
},
},
],
});

View File

@@ -0,0 +1,235 @@
import SASjs from "sasjs";
import { TestSuite } from "../types";
const specialCharData: any = {
table1: [
{
tab: "\t",
lf: "\n",
cr: "\r",
semicolon: ";semi",
percent: "%",
singleQuote: "'",
doubleQuote: '"',
crlf: "\r\n",
euro: "€euro",
banghash: "!#banghash",
},
],
};
const moreSpecialCharData: any = {
table1: [
{
speech0: '"speech',
pct: "%percent",
speech: '"speech',
slash: "\\slash",
slashWithSpecial: "\\\tslash",
macvar: "&sysuserid",
chinese: "传/傳chinese",
sigma: "Σsigma",
at: "@at",
serbian: "Српски",
dollar: "$",
},
],
};
const getWideData = () => {
const cols: any = {};
for (let i = 1; i <= 10000; i++) {
cols["col" + i] = "test" + i;
}
const data: any = {
table1: [cols],
};
return data;
};
const getTables = () => {
const tables: any = {};
for (let i = 1; i <= 100; i++) {
tables["table" + i] = [{ col1: "x", col2: "x", col3: "x", col4: "x" }];
}
return tables;
};
const getLargeDataset = () => {
const rows: any = [];
const colData: string =
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
for (let i = 1; i <= 10000; i++) {
rows.push({ col1: colData, col2: colData, col3: colData, col4: colData });
}
const data: any = {
table1: rows,
};
return data;
};
const errorAndCsrfData: any = {
error: [{ col1: "q", col2: "w", col3: "e", col4: "r" }],
_csrf: [{ col1: "q", col2: "w", col3: "e", col4: "r" }],
};
export const specialCaseTests = (adapter: SASjs): TestSuite => ({
name: "Special Cases",
tests: [
{
title: "Common special characters",
description: "Should handle common special characters",
test: () => {
return adapter.request("common/sendArr", specialCharData);
},
assertion: (res: any) => {
return (
res.table1[0][0] === specialCharData.table1[0].tab &&
res.table1[0][1] === specialCharData.table1[0].lf &&
res.table1[0][2] === specialCharData.table1[0].cr &&
res.table1[0][3] === specialCharData.table1[0].semicolon &&
res.table1[0][4] === specialCharData.table1[0].percent &&
res.table1[0][5] === specialCharData.table1[0].singleQuote &&
res.table1[0][6] === specialCharData.table1[0].doubleQuote &&
res.table1[0][7] === "\n" &&
res.table1[0][8] === specialCharData.table1[0].euro &&
res.table1[0][9] === specialCharData.table1[0].banghash
);
},
},
// {
// title: "Other special characters",
// description: "Should handle other special characters",
// test: () => {
// return adapter.request("common/sendArr", moreSpecialCharData);
// },
// assertion: (res: any) => {
// return (
// res.table1[0][0] === moreSpecialCharData.table1[0].speech0 &&
// res.table1[0][1] === moreSpecialCharData.table1[0].pct &&
// res.table1[0][2] === moreSpecialCharData.table1[0].speech &&
// res.table1[0][3] === moreSpecialCharData.table1[0].slash &&
// res.table1[0][4] === moreSpecialCharData.table1[0].slashWithSpecial &&
// res.table1[0][5] === moreSpecialCharData.table1[0].macvar &&
// res.table1[0][6] === moreSpecialCharData.table1[0].chinese &&
// res.table1[0][7] === moreSpecialCharData.table1[0].sigma &&
// res.table1[0][8] === moreSpecialCharData.table1[0].at &&
// res.table1[0][9] === moreSpecialCharData.table1[0].serbian &&
// res.table1[0][10] === moreSpecialCharData.table1[0].dollar
// );
// },
// },
// {
// title: "Wide table with sendArr",
// description: "Should handle data with 10000 columns",
// test: () => {
// return adapter.request("common/sendArr", getWideData());
// },
// assertion: (res: any) => {
// const data = getWideData();
// let result = true;
// for (let i = 0; i <= 10; i++) {
// result =
// result && res.table1[0][i] === data.table1[0]["col" + (i + 1)];
// }
// return result;
// },
// },
// {
// title: "Wide table with sendObj",
// description: "Should handle data with 10000 columns",
// test: () => {
// return adapter.request("common/sendObj", getWideData());
// },
// assertion: (res: any) => {
// const data = getWideData();
// let result = true;
// for (let i = 0; i <= 10; i++) {
// result =
// result &&
// res.table1[0]["COL" + (i + 1)] === data.table1[0]["col" + (i + 1)];
// }
// return result;
// },
// },
// {
// title: "Multiple tables",
// description: "Should handle data with 100 tables",
// test: () => {
// return adapter.request("common/sendArr", getTables());
// },
// assertion: (res: any) => {
// const data = getTables();
// return (
// res.table1[0][0] === data.table1[0].col1 &&
// res.table1[0][1] === data.table1[0].col2 &&
// res.table1[0][2] === data.table1[0].col3 &&
// res.table1[0][3] === data.table1[0].col4 &&
// res.table50[0][0] === data.table50[0].col1 &&
// res.table50[0][1] === data.table50[0].col2 &&
// res.table50[0][2] === data.table50[0].col3 &&
// res.table50[0][3] === data.table50[0].col4
// );
// },
// },
{
title: "Large dataset",
description: "Should handle 5mb of data",
test: () => {
return adapter.request("common/sendArr", getLargeDataset());
},
assertion: (res: any) => {
const data = getLargeDataset();
let result = true;
for (let i = 0; i <= 10; i++) {
result = result && res.table1[i][0] === data.table1[i][0];
}
return result;
},
},
// {
// title: "Error and _csrf tables with sendArr",
// description: "Should handle error and _csrf tables",
// test: () => {
// return adapter.request("common/sendArr", errorAndCsrfData);
// },
// assertion: (res: any) => {
// return (
// res.error[0][0] === errorAndCsrfData.error[0].col1 &&
// res.error[0][1] === errorAndCsrfData.error[0].col2 &&
// res.error[0][2] === errorAndCsrfData.error[0].col3 &&
// res.error[0][3] === errorAndCsrfData.error[0].col4 &&
// res._csrf[0][0] === errorAndCsrfData._csrf[0].col1 &&
// res._csrf[0][1] === errorAndCsrfData._csrf[0].col2 &&
// res._csrf[0][2] === errorAndCsrfData._csrf[0].col3 &&
// res._csrf[0][3] === errorAndCsrfData._csrf[0].col4
// );
// },
// },
// {
// title: "Error and _csrf tables with sendObj",
// description: "Should handle error and _csrf tables",
// test: () => {
// return adapter.request("common/sendObj", errorAndCsrfData);
// },
// assertion: (res: any) => {
// return (
// res.error[0].COL1 === errorAndCsrfData.error[0].col1 &&
// res.error[0].COL2 === errorAndCsrfData.error[0].col2 &&
// res.error[0].COL3 === errorAndCsrfData.error[0].col3 &&
// res.error[0].COL4 === errorAndCsrfData.error[0].col4 &&
// res._csrf[0].COL1 === errorAndCsrfData._csrf[0].col1 &&
// res._csrf[0].COL2 === errorAndCsrfData._csrf[0].col2 &&
// res._csrf[0].COL3 === errorAndCsrfData._csrf[0].col3 &&
// res._csrf[0].COL4 === errorAndCsrfData._csrf[0].col4
// );
// },
// },
],
});