Skip to content

Commit

Permalink
organization cmd update org name
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeSeqLabs committed Aug 28, 2023
1 parent 315e648 commit 6ac6373
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class UpdateCmd extends AbstractOrganizationsCmd {
@CommandLine.Mixin
OrganizationRefOptions organizationRefOptions;

@CommandLine.Option(names = {"--new-name"}, description = "Organization new name.")
public String newName;

@CommandLine.Option(names = {"-f", "--full-name"}, description = "Organization full name.")
public String fullName;

Expand All @@ -43,6 +46,7 @@ protected Response exec() throws ApiException, IOException {
OrganizationDbDto organization = response.getOrganization();

UpdateOrganizationRequest request = new UpdateOrganizationRequest();
request.setName(newName != null ? newName : organization.getName());
request.setFullName(fullName != null ? fullName : organization.getFullName());
request.setDescription(opts.description != null ? opts.description : organization.getDescription());
request.setLocation(opts.location != null ? opts.location : organization.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.mockserver.client.MockServerClient;
import org.mockserver.model.JsonBody;
import org.mockserver.model.MediaType;

import java.util.Arrays;
Expand All @@ -38,6 +39,7 @@
import static org.mockserver.matchers.Times.exactly;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;
import static org.mockserver.model.JsonBody.json;

class OrganizationsCmdTest extends BaseCmdTest {

Expand Down Expand Up @@ -295,6 +297,40 @@ void testUpdate(OutputType format, MockServerClient mock) {
assertOutput(format, out, new OrganizationsUpdated(27736513644467L, "organization1"));
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testUpdateName(OutputType format, MockServerClient mock) {
mock.reset();
mock.when(
request().withMethod("GET").withPath("/user-info"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("user")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/user/1264/workspaces"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("workspaces/workspaces_list")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/orgs/27736513644467"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("organizations/organizations_view")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("PUT").withPath("/orgs/27736513644467")
.withBody(json("{\"name\":\"organization2\",\"fullName\":\"sample organization\"}")),
exactly(1)
).respond(
response().withStatusCode(204)
);

ExecOut out = exec(format, mock, "organizations", "update", "-n", "organization1", "--new-name", "organization2", "-f", "sample organization");
assertOutput(format, out, new OrganizationsUpdated(27736513644467L, "organization1"));
}

@Test
void testUpdateError(MockServerClient mock) {
mock.reset();
Expand Down

0 comments on commit 6ac6373

Please sign in to comment.