Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-10 04:12:53 +01:00
DEV: Update api creatipon wizard
Dieser Commit ist enthalten in:
Ursprung
ebddcb5606
Commit
2c52459f29
1 geänderte Dateien mit 105 neuen und 23 gelöschten Zeilen
|
@ -1,10 +1,11 @@
|
||||||
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { visit } from "@ember/test-helpers";
|
import { click, select, visit } from "@ember/test-helpers";
|
||||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||||
import {
|
import {
|
||||||
getBusinessAdminWizard,
|
getBusinessAdminWizard,
|
||||||
getCustomFields,
|
getCustomFields,
|
||||||
|
getNewApi,
|
||||||
getWizard,
|
getWizard,
|
||||||
} from "../helpers/admin-wizard";
|
} from "../helpers/admin-wizard";
|
||||||
|
|
||||||
|
@ -26,7 +27,13 @@ acceptance("Admin | API tab", function (needs) {
|
||||||
return helper.response(getCustomFields);
|
return helper.response(getCustomFields);
|
||||||
});
|
});
|
||||||
server.get("/admin/wizards/api", () => {
|
server.get("/admin/wizards/api", () => {
|
||||||
return helper.response([]);
|
return helper.response([
|
||||||
|
{
|
||||||
|
name: "new_api",
|
||||||
|
title: "new API",
|
||||||
|
endpoints: [{ id: "59e3b6", name: "ag" }],
|
||||||
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
server.get("/admin/customize/user_fields", () => {
|
server.get("/admin/customize/user_fields", () => {
|
||||||
return helper.response({ user_fields: [] });
|
return helper.response({ user_fields: [] });
|
||||||
|
@ -34,22 +41,91 @@ acceptance("Admin | API tab", function (needs) {
|
||||||
server.put("/admin/wizards/api/new_api", () => {
|
server.put("/admin/wizards/api/new_api", () => {
|
||||||
return helper.response({
|
return helper.response({
|
||||||
success: "OK",
|
success: "OK",
|
||||||
|
api: {
|
||||||
name: "new_api",
|
name: "new_api",
|
||||||
|
title: "new API",
|
||||||
|
authorization: {
|
||||||
|
auth_type: "basic",
|
||||||
|
auth_url: null,
|
||||||
|
token_url: null,
|
||||||
|
client_id: null,
|
||||||
|
client_secret: null,
|
||||||
|
authorized: null,
|
||||||
|
auth_params: [],
|
||||||
|
access_token: null,
|
||||||
|
refresh_token: null,
|
||||||
|
token_expires_at: null,
|
||||||
|
token_refresh_at: null,
|
||||||
|
code: null,
|
||||||
|
username: "some_username",
|
||||||
|
password: "some_password",
|
||||||
|
},
|
||||||
|
endpoints: [
|
||||||
|
{
|
||||||
|
id: "8371de",
|
||||||
|
name: "endpoint_name",
|
||||||
|
method: "POST",
|
||||||
|
url: "https://test.api.com",
|
||||||
|
content_type: "application/json",
|
||||||
|
success_codes: [200, 100],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
log: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
server.get("/admin/wizards/api/new_api", () => {
|
||||||
|
return helper.response({
|
||||||
|
name: "new_api",
|
||||||
|
title: "new API",
|
||||||
|
authorization: {
|
||||||
|
auth_type: "basic",
|
||||||
|
auth_url: null,
|
||||||
|
token_url: null,
|
||||||
|
client_id: null,
|
||||||
|
client_secret: null,
|
||||||
|
authorized: null,
|
||||||
|
auth_params: [],
|
||||||
|
access_token: null,
|
||||||
|
refresh_token: null,
|
||||||
|
token_expires_at: null,
|
||||||
|
token_refresh_at: null,
|
||||||
|
code: null,
|
||||||
|
username: "some_username",
|
||||||
|
password: "some_password",
|
||||||
|
},
|
||||||
|
endpoints: [
|
||||||
|
{
|
||||||
|
id: "8371de",
|
||||||
|
name: "endpoint_name",
|
||||||
|
method: "POST",
|
||||||
|
url: "https://test.api.com",
|
||||||
|
content_type: "application/json",
|
||||||
|
success_codes: [200, 100],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
log: [],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Visit API tab", async (assert) => {
|
test("Visit API tab", async function (assert) {
|
||||||
await visit("/admin/wizards/api");
|
await visit("/admin/wizards/api");
|
||||||
const list = find(".admin-controls li");
|
const list = find(".admin-controls li");
|
||||||
const count = list.length;
|
const count = list.length;
|
||||||
assert.equal(count, 6, "There should be 6 admin tabs");
|
assert.equal(count, 6, "There should be 6 admin tabs");
|
||||||
|
|
||||||
// create new api
|
// create new api
|
||||||
await click('button:contains("Create API")');
|
await click(".admin-wizard-controls button");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
query(".wizard-header.large").innerText.includes("New API"),
|
query(".wizard-header.large").innerText.includes("New API"),
|
||||||
"it displays API creation message"
|
"it displays API creation message"
|
||||||
);
|
);
|
||||||
|
assert.equal(
|
||||||
|
currentURL(),
|
||||||
|
"/admin/wizards/api/create",
|
||||||
|
"clicking the button navigates to the correct URL"
|
||||||
|
);
|
||||||
// fill data
|
// fill data
|
||||||
await fillIn('.metadata input[placeholder="Display name"]', "new API");
|
await fillIn('.metadata input[placeholder="Display name"]', "new API");
|
||||||
await fillIn('.metadata input[placeholder="Underscored"]', "new_api");
|
await fillIn('.metadata input[placeholder="Underscored"]', "new_api");
|
||||||
|
@ -66,7 +142,7 @@ acceptance("Admin | API tab", function (needs) {
|
||||||
".wizard-api-authentication .settings .control-group:eq(2) .controls input",
|
".wizard-api-authentication .settings .control-group:eq(2) .controls input",
|
||||||
"some_password"
|
"some_password"
|
||||||
);
|
);
|
||||||
await click('.wizard-api-endpoints button:contains("Add endpoint")');
|
await click(".wizard-api-endpoints button");
|
||||||
await fillIn(
|
await fillIn(
|
||||||
'.wizard-api-endpoints .endpoint .top input[placeholder="Endpoint name"]',
|
'.wizard-api-endpoints .endpoint .top input[placeholder="Endpoint name"]',
|
||||||
"endpoint_name"
|
"endpoint_name"
|
||||||
|
@ -75,29 +151,35 @@ acceptance("Admin | API tab", function (needs) {
|
||||||
'.wizard-api-endpoints .endpoint .top input[placeholder="Enter a url"]',
|
'.wizard-api-endpoints .endpoint .top input[placeholder="Enter a url"]',
|
||||||
"https://test.api.com"
|
"https://test.api.com"
|
||||||
);
|
);
|
||||||
let endpointMethodDropdown = await selectKit(
|
const endpointMethodDropdown = await selectKit(
|
||||||
'.wizard-api-endpoints .endpoint .bottom details:has(summary[name="Filter by: Select a method"])'
|
'.wizard-api-endpoints .endpoint .bottom details:has(summary[name="Filter by: Select a method"])'
|
||||||
);
|
);
|
||||||
await endpointMethodDropdown.expand();
|
await endpointMethodDropdown.expand();
|
||||||
await endpointMethodDropdown.selectRowByValue("POST");
|
await endpointMethodDropdown.selectRowByValue("POST");
|
||||||
|
|
||||||
// let successCodesDropdown = await selectKit(
|
const contentTypeDropdown = await selectKit(
|
||||||
// ".wizard-api-endpoints .endpoint .bottom .select-kit .multi-select"
|
'.wizard-api-endpoints .endpoint .bottom details:has(summary[name="Filter by: Select a content type"])'
|
||||||
// );
|
);
|
||||||
// await successCodesDropdown.expand();
|
await contentTypeDropdown.expand();
|
||||||
// await successCodesDropdown.selectRowByValue("200");
|
await contentTypeDropdown.selectRowByValue("application/json");
|
||||||
pauseTest();
|
|
||||||
// let contentTypeDropdown = await selectKit(
|
|
||||||
// '.wizard-api-endpoints .endpoint .bottom details:has(summary[name="Filter by: Select a content type"])'
|
|
||||||
// );
|
|
||||||
// await contentTypeDropdown.expand();
|
|
||||||
// await contentTypeDropdown.selectRowByValue("application/JSON");
|
|
||||||
|
|
||||||
// const contentTypeDropdown = selectKit(
|
const successCodesDropdown = await selectKit(
|
||||||
// ".wizard-api-endpoints .endpoint .bottom details"
|
".wizard-api-endpoints .endpoint .bottom details.multi-select"
|
||||||
// );
|
);
|
||||||
// await contentTypeDropdown.expand();
|
await successCodesDropdown.expand();
|
||||||
// await contentTypeDropdown.selectRowByValue("application/JSON");
|
await successCodesDropdown.selectRowByValue(200);
|
||||||
// send a request
|
await successCodesDropdown.selectRowByValue(100);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
successCodesDropdown.header().value(),
|
||||||
|
"200,100",
|
||||||
|
"group should be set"
|
||||||
|
);
|
||||||
|
await click(".wizard-api-header.page button.btn-primary");
|
||||||
|
assert.equal(
|
||||||
|
currentURL(),
|
||||||
|
"/admin/wizards/api/new_api",
|
||||||
|
"clicking the button navigates to the correct URL"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Laden …
In neuem Issue referenzieren