Skip to content

Commit

Permalink
#390 transformed conversations test with multiple conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyprian Laskowski authored and cyplas committed Dec 12, 2022
1 parent 4eb1ce2 commit 0ae326c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 57 deletions.
56 changes: 54 additions & 2 deletions app/conversations/tests/test_conversations_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,59 @@ def test_create_conversation_successful(client_with_user_and_header, accept_json
), 'Successful creation should give "conversation created" message.'
assert (
response.json["conversationId"] == response.json["conversationId"].lower()
), "conversationId uuid should be lower case"
), "conversationId uuid should be lower case."
assert is_uuid(
response.json["conversationId"]
), "conversationId is not a valid uuid"
), "conversationId is not a valid uuid."


@pytest.mark.integration
def test_create_conversations_successful(client_with_user_and_header, accept_json):
client, _, session_header, _ = client_with_user_and_header
url_create = url_for("conversations.create_conversation_invite")
for i in range(3):
client.post(
url_create,
headers=session_header + accept_json,
json={"invitedUserName": faker.name()}
)
url_list = url_for("conversations.get_conversations")
response = client.get(
url_list,
headers=session_header + accept_json
)
assert isinstance(response.json["conversations"], list), response.json

for conversation in response.json["conversations"]:

assert "conversationId" in conversation.keys(), "Conversation must include conversationId."
assert conversation["conversationId"] == conversation["conversationId"].upper(), "conversationId uuid must be upper case."
assert is_uuid(conversation["conversationId"]), "conversationId must be a valid uuid."

assert "state" in conversation.keys(), "Conversation must include state."
assert isinstance(conversation["state"], int), "state must be an int."

assert "userA" in conversation.keys(), "Conversation must include userA."
assert isinstance(conversation["userA"], dict), "userA must be a dict."

assert "sessionId" in conversation["userA"].keys(), "userA must include sessionId."
assert conversation["userA"]["sessionId"] == conversation["userA"]["sessionId"].upper(), "userA sessionId uuid must be upper case."
assert is_uuid(conversation["userA"]["sessionId"]), "userA sessionId uuid must be a valid uuid."

assert "id" in conversation["userA"].keys(), "userA must include id."
assert conversation["userA"]["id"] == conversation["userA"]["id"].upper(), "userA id uuid must be upper case."
assert is_uuid(conversation["userA"]["id"]), "userA id uuid must be a valid uuid."

assert "name" in conversation["userA"].keys(), "userA must include name."
assert isinstance(conversation["userA"]["name"], str), "userA name must be a str."

assert "userB" in conversation.keys(), "Conversation must include userB."
assert isinstance(conversation["userB"], dict), "userB must be a dict."

assert "name" in conversation["userB"].keys(), "userB must include name."
assert isinstance(conversation["userB"]["name"], str), "userB name must be a str."

assert "userARating" in conversation.keys(), "Conversation must include userARating."
assert "consent" in conversation.keys(), "Conversation must include consent."
assert "conversationTimestamp" in conversation.keys(), "Conversation must include conversationTimestamp."
assert "alignmentScoresId" in conversation.keys(), "Conversation must include alignmentScoresId."
55 changes: 0 additions & 55 deletions cypress/e2e/conversations.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ let set_one_quizId;
let user;
let accessToken;
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}/;
const uuidFormatChecker_UpperCase = /[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/;
let requestBody;
let invitedUserName;

Expand Down Expand Up @@ -39,58 +36,6 @@ describe("'/conversation' endpoint", () => {
});
});

it("should get conversations", () => {
//Create many conversation
let i = 0;
while (i < 3) {
//Generate a username to be invited
requestBody = {
"invitedUserName": faker.name.firstName()
};
expect(requestBody).to.be.an("object");
expect(requestBody.invitedUserName).to.be.a("string");

//Create many conversation
cy.conversationEndpoint(requestBody, accessToken, session_Id);
i++;
}

//Get conversations and validate the response body of each conversation
cy.conversationsEndpoint(accessToken, session_Id)
.should((response) => {
expect(response.body.conversations).to.be.an("array");
for (var conversationIndex in response.body.conversations) {
expect(response.body.conversations[conversationIndex]).to.be.an("object");

expect(response.body.conversations[conversationIndex]).to.have.property("conversationId");
expect(response.body.conversations[conversationIndex].conversationId).to.be.a("string");
expect(response.body.conversations[conversationIndex].conversationId).to.match(uuidFormatChecker_UpperCase);

expect(response.body.conversations[conversationIndex]).to.have.property("state");
expect(response.body.conversations[conversationIndex].state).to.be.a("number");

expect(response.body.conversations[conversationIndex]).to.have.property("userA");
expect(response.body.conversations[conversationIndex].userA).to.be.an("object");
expect(response.body.conversations[conversationIndex].userA).to.have.property("sessionId");
expect(response.body.conversations[conversationIndex].userA.sessionId).to.match(uuidFormatChecker_UpperCase);
expect(response.body.conversations[conversationIndex].userA).to.have.property("id");
expect(response.body.conversations[conversationIndex].userA.id).to.match(uuidFormatChecker_UpperCase);
expect(response.body.conversations[conversationIndex].userA).to.have.property("name");
expect(response.body.conversations[conversationIndex].userA.name).to.be.a("string");

expect(response.body.conversations[conversationIndex]).to.have.property("userB");
expect(response.body.conversations[conversationIndex].userB).to.be.an("object");
expect(response.body.conversations[conversationIndex].userB).to.have.property("name");
expect(response.body.conversations[conversationIndex].userB.name).to.be.a("string");

expect(response.body.conversations[conversationIndex]).to.have.property("userARating");
expect(response.body.conversations[conversationIndex]).to.have.property("consent");
expect(response.body.conversations[conversationIndex]).to.have.property("conversationTimestamp");
expect(response.body.conversations[conversationIndex]).to.have.property("alignmentScoresId");
}
});
});

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 0ae326c

Please sign in to comment.