Skip to content

Commit

Permalink
#390 transformed invalid invitee name tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyprian Laskowski committed Oct 24, 2022
1 parent a64979c commit 7de3de3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 68 deletions.
26 changes: 25 additions & 1 deletion app/conversations/tests/test_conversations_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,35 @@ def test_conversation_request_unauthorized(client_with_user_and_header, accept_j

@pytest.mark.integration
def test_get_conversations_empty(client_with_user_and_header, accept_json):
client, user, session_header, _ = client_with_user_and_header
client, _, session_header, _ = client_with_user_and_header
url = url_for("conversations.get_conversations")
response = client.get(
url,
headers=session_header + accept_json,
)
assert response.status_code == 200, str(response.json)
assert response.json == {"conversations": []}


@pytest.mark.parametrize(
"invited_user_name",
[
"",
"managementmanagementm",
"managementmanagementmanagementmanagementmanagementm",
],
)
@pytest.mark.integration
def test_create_conversation_with_invalid_invitee(
invited_user_name, client_with_user_and_header, accept_json
):
client, _, session_header, _ = client_with_user_and_header
url = url_for("conversations.create_conversation_invite")
response = client.post(
url,
headers=session_header + accept_json,
json={"invitedUserName": invited_user_name},
)
assert (
response.status_code == 400
), "Must provide a JSON body with the name of the invited user."
67 changes: 0 additions & 67 deletions cypress/e2e/conversations.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ let session_Id;
let set_one_quizId;
let user;
let accessToken;
const invalidInvitedUsername = "Must provide a name that is up to 20 characters long.";
const missingJSONBodyMessage = "Must provide a JSON body with the name of the invited user.";
const SESSION_UUIDNotInDBMessage = "SESSION_UUID is not in the db.";
const uuidFormatChecker_LowerCase = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
Expand Down Expand Up @@ -117,72 +116,6 @@ describe("'/conversation' endpoint", () => {
});
});

it("should not allow creating a conversation with an invited_username of 0 characters", () => {
//Generate a username to be invited
requestBody = {
"invitedUserName": ""
}
expect(requestBody.invitedUserName).to.be.a("string");

//Create a conversation and test the response body
cy.conversationEndpoint(requestBody, accessToken, session_Id).should((response) => {
expect(response.status).to.equal(400);
expect(response.headers["content-type"]).to.equal(
"application/json"
);
expect(response.body).to.be.an("object");
expect(response.body).to.have.property("error");
expect(response.body.error).to.be.a("string");
expect(response.body.error).to.satisfy(function (s) {
return s === invalidInvitedUsername;
});
});
});

it("should not allow creating a conversation with an invited_username of 21 characters", () => {
//Generate a username to be invited
requestBody = {
"invitedUserName": "managementmanagementm"
}
expect(requestBody.invitedUserName).to.be.a("string");

//Create a conversation and test the response body
cy.conversationEndpoint(requestBody, accessToken, session_Id).should((response) => {
expect(response.status).to.equal(400);
expect(response.headers["content-type"]).to.equal(
"application/json"
);
expect(response.body).to.be.an("object");
expect(response.body).to.have.property("error");
expect(response.body.error).to.be.a("string");
expect(response.body.error).to.satisfy(function (s) {
return s === invalidInvitedUsername;
});
});
});

it("should not allow creating a conversation with an invited_username greater than 20 characters", () => {
//Generate a username to be invited
requestBody = {
"invitedUserName": "managementmanagementmanagementmanagementmanagementm"
}
expect(requestBody.invitedUserName).to.be.a("string");

//Create a conversation and test the response body
cy.conversationEndpoint(requestBody, accessToken, session_Id).should((response) => {
expect(response.status).to.equal(400);
expect(response.headers["content-type"]).to.equal(
"application/json"
);
expect(response.body).to.be.an("object");
expect(response.body).to.have.property("error");
expect(response.body.error).to.be.a("string");
expect(response.body.error).to.satisfy(function (s) {
return s === invalidInvitedUsername;
});
});
});

it("should not allow creating a conversation without providing a JSON Body containing invited_username", () => {
//Generate a username to be invited
invitedUserName = faker.name.firstName();
Expand Down

0 comments on commit 7de3de3

Please sign in to comment.