Skip to content

Commit

Permalink
tests: add unit test for getSchemaOptions to verify CLOUD_OPTIONS_PRO…
Browse files Browse the repository at this point in the history
…VIDER_OVERRIDE override
  • Loading branch information
andre-code committed Jan 13, 2025
1 parent 860d02f commit 85bc105
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
"noreferrer",
"nowrap",
"nteract",
"ntlm",
"nullable",
"oauth2",
"objectstores",
Expand Down Expand Up @@ -249,6 +250,7 @@
"serializable",
"sftp",
"shareability",
"sharepoint",
"slugify",
"starrers",
"statuspage",
Expand Down
224 changes: 223 additions & 1 deletion client/src/features/project/utils/projectCloudStorage.utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { storageDefinitionFromConfig } from "./projectCloudStorage.utils";
import { CloudStorageSchema } from "../components/cloudStorage/projectCloudStorage.types.ts";
import {
getSchemaOptions,
storageDefinitionFromConfig,
} from "./projectCloudStorage.utils";

describe("storageDefinitionFromConfig", () => {
it("should return the correct storage definition", () => {
Expand Down Expand Up @@ -88,4 +92,222 @@ describe("storageDefinitionFromConfig", () => {
target_path: "external_storage/aws",
});
});

it("should return the correct schema options", () => {
const schema: CloudStorageSchema[] = [
{
name: "PolyBox",
description: "Polybox",
prefix: "polybox",
options: [
{
name: "url",
help: "URL of http host to connect to.\n\nE.g. https://example.com.",
provider: "personal",
default: "https://polybox.ethz.ch/remote.php/webdav/",
default_str: "",
required: false,
sensitive: false,
advanced: false,
exclusive: false,
type: "string",
value: "",
examples: [],
ispassword: false,
datatype: "string",
hide: false,
filteredExamples: [],
},
{
name: "user",
help: "User name.\n\nIn case NTLM authentication is used, the username should be in the format 'Domain\\User'.",
provider: "personal",
default: "",
default_str: "",
required: false,
sensitive: false,
advanced: false,
exclusive: false,
type: "string",
value: "",
examples: [],
ispassword: false,
datatype: "string",
hide: false,
filteredExamples: [],
},
{
name: "pass",
help: "Password.",
provider: "",
default: "",
default_str: "",
required: false,
sensitive: true,
advanced: false,
exclusive: false,
type: "string",
value: "",
examples: [],
ispassword: true,
datatype: "string",
hide: false,
filteredExamples: [],
},
{
name: "bearer_token",
help: "Bearer token instead of user/pass (e.g. a Macaroon).",
provider: "personal",
default: "",
default_str: "",
required: false,
sensitive: true,
advanced: false,
exclusive: false,
type: "string",
value: "",
examples: [],
ispassword: false,
datatype: "string",
hide: false,
filteredExamples: [],
},
{
name: "bearer_token_command",
help: "Command to run to get a bearer token.",
provider: "personal",
default: "",
default_str: "",
required: false,
sensitive: false,
advanced: true,
exclusive: false,
type: "string",
value: "",
examples: [],
ispassword: false,
datatype: "string",
hide: false,
filteredExamples: [],
},
{
name: "encoding",
help: "",
provider: "",
default: "",
default_str: "",
required: false,
sensitive: false,
advanced: true,
exclusive: false,
type: "string",
value: "",
examples: [],
ispassword: false,
datatype: "string",
hide: false,
filteredExamples: [],
},
{
name: "headers",
help: 'Set HTTP headers for all transactions.\n\nUse this to set additional HTTP headers for all transactions\n\nThe input format is comma separated list of key,value pairs. Standard\n[CSV encoding](https://godoc.org/encoding/csv) may be used.\n\nFor example, to set a Cookie use \'Cookie,name=value\', or \'"Cookie","name=value"\'.\n\nYou can set multiple headers, e.g. \'"Cookie","name=value","Authorization","xxx"\'.\n',
provider: "personal",
default: "",
default_str: "",
required: false,
sensitive: false,
advanced: true,
exclusive: false,
type: "CommaSepList",
value: "",
examples: [],
ispassword: false,
datatype: "string",
hide: false,
filteredExamples: [],
},
{
name: "pacer_min_sleep",
help: "Minimum time to sleep between API calls.",
provider: "",
default: 10000000,
default_str: "10ms",
required: false,
sensitive: false,
advanced: true,
exclusive: false,
type: "Duration",
value: "",
examples: [],
ispassword: false,
datatype: "string",
hide: false,
filteredExamples: [],
},
{
name: "provider",
help: "Choose the mode to access the data source.",
provider: "",
default: "",
default_str: "",
examples: [
{
value: "personal",
help: "Connect to your personal storage space. This data connector cannot be used to share access to a folder.",
provider: "",
},
{
value: "shared",
help: "Connect a 'public' folder shared with others. A 'public' folder may or may not be protected with a password.",
provider: "",
},
],
required: true,
sensitive: false,
advanced: false,
exclusive: true,
type: "string",
value: "",
ispassword: false,
datatype: "string",
hide: false,
filteredExamples: [],
},
{
name: "public_link",
help: "Shared folder link. E.g., https://polybox.ethz.ch/index.php/s/8NffJ3rFyHaVyyy",
provider: "shared",
default: "",
default_str: "",
required: true,
sensitive: false,
advanced: false,
exclusive: false,
type: "string",
value: "",
examples: [],
ispassword: false,
datatype: "string",
hide: false,
filteredExamples: [],
},
],
},
];
const result = getSchemaOptions(schema, false, "polybox", "shared");
const passOption = result?.find((o) => o.name === "pass");
expect(passOption?.help).toEqual(
"If there is a password for the folder, enter that in the password field. Otherwise, leave it blank"
);
expect(passOption?.friendlyName).toEqual("Password");

const resultPersonal = getSchemaOptions(
schema,
false,
"polybox",
"personal"
);
const passOptionPersonal = resultPersonal?.find((o) => o.name === "pass");
expect(passOptionPersonal?.friendlyName).toEqual("Token (or password)");
});
});

0 comments on commit 85bc105

Please sign in to comment.