-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow passing client options to administration commands. Added basic …
…tests for administration commands.
- Loading branch information
1 parent
a6b4c16
commit 44e193b
Showing
4 changed files
with
257 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { | ||
expectC8yClientRequest, | ||
initRequestStub, | ||
stubResponses, | ||
} from "../support/util"; | ||
const { _ } = Cypress; | ||
|
||
declare global { | ||
interface Window { | ||
fetchStub: Cypress.Agent<sinon.SinonStub>; | ||
} | ||
} | ||
|
||
describe("administration", () => { | ||
beforeEach(() => { | ||
Cypress.env("C8Y_USERNAME", undefined); | ||
Cypress.env("C8Y_PASSWORD", undefined); | ||
Cypress.env("C8Y_TENANT", undefined); | ||
|
||
initRequestStub(); | ||
stubResponses([ | ||
new window.Response(JSON.stringify({ name: "t1234" }), { | ||
status: 200, | ||
statusText: "OK", | ||
headers: { "content-type": "application/json" }, | ||
}), | ||
]); | ||
}); | ||
|
||
context("deleteUser", () => { | ||
it("should delete user from user options", function () { | ||
stubResponses([ | ||
new window.Response(null, { | ||
status: 204, | ||
statusText: "OK", | ||
headers: { "content-type": "application/json" }, | ||
}), | ||
]); | ||
cy.getAuth({ user: "admin", password: "mypassword", tenant: "t12345678" }) | ||
.deleteUser({ userName: "test", displayName: "wewe" }) | ||
.then((response) => { | ||
expect(response.status).to.eq(204); | ||
expectC8yClientRequest({ | ||
url: `${Cypress.config().baseUrl}/user/t12345678/users/test`, | ||
auth: { | ||
user: "admin", | ||
password: "mypassword", | ||
tenant: "t12345678", | ||
}, | ||
headers: { UseXBasic: true, "content-type": "application/json" }, | ||
method: "DELETE", | ||
}); | ||
}); | ||
}); | ||
|
||
it("should use client options", function () { | ||
stubResponses([ | ||
new window.Response(null, { | ||
status: 404, | ||
statusText: "OK", | ||
headers: { "content-type": "application/json" }, | ||
}), | ||
]); | ||
cy.getAuth({ user: "admin", password: "mypassword", tenant: "t12345678" }) | ||
.deleteUser( | ||
{ userName: "test", displayName: "wewe" }, | ||
{ baseUrl: "https://abc.def.com", failOnStatusCode: true }, | ||
) | ||
.then((response) => { | ||
expect(response.status).to.eq(404); | ||
expectC8yClientRequest({ | ||
url: `https://abc.def.com/user/t12345678/users/test`, | ||
auth: { | ||
user: "admin", | ||
password: "mypassword", | ||
tenant: "t12345678", | ||
}, | ||
headers: { UseXBasic: true, "content-type": "application/json" }, | ||
method: "DELETE", | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
context("getCurrentTenant", () => { | ||
it("should get current tenant using c8yclient", function () { | ||
cy.getAuth({ user: "admin", password: "mypassword", tenant: "t12345678" }) | ||
.getCurrentTenant() | ||
.then((response) => { | ||
expect(response.status).to.eq(200); | ||
expect(response.body.name).to.eq("t1234"); | ||
expectC8yClientRequest({ | ||
url: `${Cypress.config().baseUrl}/tenant/currentTenant`, | ||
auth: { | ||
user: "admin", | ||
password: "mypassword", | ||
tenant: "t12345678", | ||
}, | ||
headers: { UseXBasic: true, "content-type": "application/json" }, | ||
}); | ||
}); | ||
}); | ||
|
||
it("should use client options", function () { | ||
cy.getAuth({ user: "admin", password: "mypassword", tenant: "t12345678" }) | ||
.getCurrentTenant({ | ||
baseUrl: "https://abc.def.com", | ||
}) | ||
.then((response) => { | ||
expect(response.status).to.eq(200); | ||
expectC8yClientRequest({ | ||
url: `https://abc.def.com/tenant/currentTenant`, | ||
auth: { | ||
user: "admin", | ||
password: "mypassword", | ||
tenant: "t12345678", | ||
}, | ||
headers: { UseXBasic: true, "content-type": "application/json" }, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
context("getTenantId", () => { | ||
it("should get tenant id using c8yclient", function () { | ||
cy.getAuth({ user: "admin", password: "mypassword" }) | ||
.getTenantId() | ||
.then((id) => { | ||
expect(id).to.eq("t1234"); | ||
expect(window.fetchStub.callCount).to.equal(1); | ||
}); | ||
}); | ||
|
||
it("should use tenant id from auth", function () { | ||
cy.getAuth({ user: "admin", password: "mypassword", tenant: "t247652" }) | ||
.getTenantId() | ||
.then((id) => { | ||
expect(id).to.eq("t247652"); | ||
expect(window.fetchStub.callCount).to.equal(0); | ||
}); | ||
}); | ||
|
||
it("should use tenant id from env variable", function () { | ||
Cypress.env("C8Y_TENANT", "t232447652") | ||
cy.getAuth({ user: "admin", password: "mypassword" }) | ||
.getTenantId() | ||
.then((id) => { | ||
expect(id).to.eq("t232447652"); | ||
expect(window.fetchStub.callCount).to.equal(0); | ||
}); | ||
}); | ||
|
||
it("should prefer tenant id from auth", function () { | ||
Cypress.env("C8Y_TENANT", "t232447652") | ||
cy.getAuth({ user: "admin", password: "mypassword", tenant: "t324678" }) | ||
.getTenantId() | ||
.then((id) => { | ||
expect(id).to.eq("t324678"); | ||
expect(window.fetchStub.callCount).to.equal(0); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.