Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12048] Migrate tests for DeleteAccountActionTest #13200

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/teammates/ui/webapi/DeleteAccountAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Action: deletes an existing account (either student or instructor).
*/
class DeleteAccountAction extends AdminOnlyAction {
public class DeleteAccountAction extends AdminOnlyAction {

@Override
public JsonResult execute() {
Expand Down
54 changes: 54 additions & 0 deletions src/test/java/teammates/sqlui/webapi/DeleteAccountActionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package teammates.sqlui.webapi;

import org.testng.annotations.Test;

import teammates.common.datatransfer.InstructorPrivileges;
import teammates.common.util.Const;
import teammates.storage.sqlentity.Account;
import teammates.storage.sqlentity.Course;
import teammates.storage.sqlentity.Instructor;
import teammates.ui.output.MessageOutput;
import teammates.ui.webapi.DeleteAccountAction;

/**
* SUT: {@link DeleteAccountAction}.
*/
public class DeleteAccountActionTest extends BaseActionTest<DeleteAccountAction> {
String googleId = "user-googleId";

@Override
protected String getActionUri() {
return Const.ResourceURIs.ACCOUNT;
}

@Override
protected String getRequestMethod() {
return DELETE;
}

@Test
protected void textExecute_accountDoesNotExist_failSilently() {
String[] params = {
Const.ParamsNames.INSTRUCTOR_ID, "non-existing-account",
};
DeleteAccountAction action = getAction(params);
MessageOutput actionOutput = (MessageOutput) getJsonResult(action).getOutput();
assertEquals("Account is successfully deleted.", actionOutput.getMessage());
}

@Test
protected void testExecute_accountExists_success() {
Course stubCourse = new Course("course-id", "name", Const.DEFAULT_TIME_ZONE, "institute");
Account stubAccount = new Account(googleId, "name", "[email protected]");
Instructor instructor = new Instructor(stubCourse, "name", "[email protected]",
false, "", null, new InstructorPrivileges());
instructor.setAccount(stubAccount);
String[] params = {
Const.ParamsNames.INSTRUCTOR_ID, instructor.getGoogleId(),
};
DeleteAccountAction action = getAction(params);
MessageOutput actionOutput = (MessageOutput) getJsonResult(action).getOutput();
assertEquals("Account is successfully deleted.", actionOutput.getMessage());
assertNull(mockLogic.getInstructorByGoogleId(stubCourse.getId(), instructor.getGoogleId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,48 @@ describe('VisibilityCapabilityPipe', () => {
const pipe: VisibilityCapabilityPipe = new VisibilityCapabilityPipe();
expect(pipe).toBeTruthy();
});
it('should return the correct message when all controls are true', () => {
const pipe: VisibilityCapabilityPipe = new VisibilityCapabilityPipe();
const controls = {
SHOW_RESPONSE: true,
SHOW_RECIPIENT_NAME: true,
SHOW_GIVER_NAME: true,
};
const result = pipe.transform(controls);
expect(result).toBe('can see your response, the name of the recipient, and your name');
});

it('should return the correct message when only SHOW_RECIPIENT_NAME is true', () => {
const pipe: VisibilityCapabilityPipe = new VisibilityCapabilityPipe();
const controls = {
SHOW_RESPONSE: true,
SHOW_RECIPIENT_NAME: true,
SHOW_GIVER_NAME: false,
};
const result = pipe.transform(controls);
expect(result).toBe('can see your response, the name of the recipient, but not your name');
});

it('should return the correct message when only SHOW_GIVER_NAME is true', () => {
const pipe: VisibilityCapabilityPipe = new VisibilityCapabilityPipe();
const controls = {
SHOW_RESPONSE: true,
SHOW_RECIPIENT_NAME: false,
SHOW_GIVER_NAME: true,
};
const result = pipe.transform(controls);
expect(result).toBe('can see your response, and your name, but not the name of the recipient');
});

it('should return the correct message when all controls are false', () => {
const pipe: VisibilityCapabilityPipe = new VisibilityCapabilityPipe();
const controls = {
SHOW_RESPONSE: false,
SHOW_RECIPIENT_NAME: false,
SHOW_GIVER_NAME: false,
};
const result = pipe.transform(controls);
expect(result).toBe('can see your response, but not the name of the recipient, or your name');
});

});
Original file line number Diff line number Diff line change
@@ -1,8 +1,73 @@
import { VisibilityEntityNamePipe } from './visibility-entity-name.pipe';
import {
FeedbackParticipantType,
FeedbackVisibilityType,
NumberOfEntitiesToGiveFeedbackToSetting,
} from '../../../types/api-output';

describe('VisibilityEntityNamePipe', () => {
it('create an instance', () => {
const pipe: VisibilityEntityNamePipe = new VisibilityEntityNamePipe();
expect(pipe).toBeTruthy();
});

it('should return the correct entity name when the visibility type is RECIPIENT and recipient type is '
+ 'INSTRUCTORS ', () => {
const pipe: VisibilityEntityNamePipe = new VisibilityEntityNamePipe();
const result = pipe.transform(FeedbackVisibilityType.RECIPIENT, FeedbackParticipantType.INSTRUCTORS);
expect(result).toBe('The receiving instructor');
});

it('should return the correct entity name when the visibility type is RECIPIENT and recipient type is '
+ 'STUDENTS', () => {
const pipe: VisibilityEntityNamePipe = new VisibilityEntityNamePipe();
const result = pipe.transform(FeedbackVisibilityType.RECIPIENT, FeedbackParticipantType.STUDENTS);
expect(result).toBe('The receiving student');
});

it('should return the correct entity name when the visibility type is RECIPIENT and recipient type is '
+ 'TEAMS', () => {
const pipe: VisibilityEntityNamePipe = new VisibilityEntityNamePipe();
const result = pipe.transform(FeedbackVisibilityType.RECIPIENT, FeedbackParticipantType.TEAMS);
expect(result).toBe('The receiving team');
});

it('should return the correct entity name when the visibility type is RECIPIENT and recipient type is '
+ 'NONE', () => {
const pipe: VisibilityEntityNamePipe = new VisibilityEntityNamePipe();
const result = pipe.transform(FeedbackVisibilityType.RECIPIENT, FeedbackParticipantType.NONE);
expect(result).toBe('unknown');
});

it('should return the correct entity name when the visibility type is GIVEN_TEAM_MEMBERS', () => {
const pipe: VisibilityEntityNamePipe = new VisibilityEntityNamePipe();
const result = pipe.transform(FeedbackVisibilityType.GIVER_TEAM_MEMBERS);
expect(result).toBe('Your team members');
});

it('should return the correct entity name when the visibility type is INSTRUCTORS', () => {
const pipe: VisibilityEntityNamePipe = new VisibilityEntityNamePipe();
const result = pipe.transform(FeedbackVisibilityType.INSTRUCTORS);
expect(result).toBe('Instructors in this course');
});

it('should return the correct entity name when the visibility type is STUDENTS', () => {
const pipe: VisibilityEntityNamePipe = new VisibilityEntityNamePipe();
const result = pipe.transform(FeedbackVisibilityType.STUDENTS);
expect(result).toBe('Other students in the course');
});

it('should return the correct entity name when the visibility type is RECIPIENT_TEAM_MEMBERS', () => {
const pipe: VisibilityEntityNamePipe = new VisibilityEntityNamePipe();
const result = pipe.transform(FeedbackVisibilityType.RECIPIENT_TEAM_MEMBERS);
expect(result).toBe("The recipient's team members");
});

it('should return plural form of entity name when the visibility type is RECIPIENT and the number of entities '
+ 'to give feedback to UNLIMITED', () => {
const pipe: VisibilityEntityNamePipe = new VisibilityEntityNamePipe();
const result = pipe.transform(FeedbackVisibilityType.RECIPIENT, FeedbackParticipantType.STUDENTS,
NumberOfEntitiesToGiveFeedbackToSetting.UNLIMITED);
expect(result).toBe('The receiving students');
});
});
Loading