Skip to content

Commit

Permalink
Add organization id to theme (#365)
Browse files Browse the repository at this point in the history
The organization could be removed and wherever rendered can be updated to fetch the organization by id.

Note the non default constructor is for testing purposes.
  • Loading branch information
wwelling authored Aug 10, 2023
1 parent ec09103 commit 1339e65
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class Theme extends Named {
@Column(nullable = false)
private String organization;

@Column(nullable = false)
private String organizationId;

@Column(nullable = false)
private boolean active;

Expand Down Expand Up @@ -52,10 +55,11 @@ public Theme() {
this.variables = new ArrayList<Style>();
}

public Theme(String name, String organization) {
public Theme(String name, String organization, String organizationId) {
this();
setName(name);
this.organization = organization;
this.organizationId = organizationId;
}

public String getOrganization() {
Expand All @@ -66,6 +70,14 @@ public void setOrganization(String organization) {
this.organization = organization;
}

public String getOrganizationId() {
return organizationId;
}

public void setOrganizationId(String organizationId) {
this.organizationId = organizationId;
}

public boolean isActive() {
return active;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/defaults/themes.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: Scholars
organization: Scholars University
organizationId: n000001
active: false
home:
heroesNavigable: false
Expand Down Expand Up @@ -159,6 +160,7 @@
value: "#F5B041"
- name: TAMU
organization: Texas A&M University
organizationId: n5d3837d6
active: true
home:
heroesNavigable: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ public class EntityMessageTest {

@Test
public void testCreateEntityMessage() {
CreateEntityMessage<Theme> createThemeMessage = new CreateEntityMessage<Theme>(new Theme("Test", "Testing Unlimited"));
CreateEntityMessage<Theme> createThemeMessage = new CreateEntityMessage<Theme>(new Theme("Test", "Testing Unlimited", "n000001"));
assertNotNull(createThemeMessage);
assertEquals("Test", createThemeMessage.getEntity().getName());
assertEquals("Testing Unlimited", createThemeMessage.getEntity().getOrganization());
assertEquals("n000001", createThemeMessage.getEntity().getOrganizationId());
assertEquals(CREATE, createThemeMessage.getAction());
}

@Test
public void testUpdateEntityMessage() {
UpdateEntityMessage<Theme> updateThemeMessage = new UpdateEntityMessage<Theme>(new Theme("Test", "Testing Unlimited"));
UpdateEntityMessage<Theme> updateThemeMessage = new UpdateEntityMessage<Theme>(new Theme("Test", "Testing Unlimited", "n000001"));
assertNotNull(updateThemeMessage);
assertEquals("Test", updateThemeMessage.getEntity().getName());
assertEquals("Testing Unlimited", updateThemeMessage.getEntity().getOrganization());
assertEquals("n000001", updateThemeMessage.getEntity().getOrganizationId());
assertEquals(UPDATE, updateThemeMessage.getAction());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class ThemeIntegrationTest extends UserIntegrationTest {
protected ThemeRepo themeRepo;

protected Theme getMockTheme() {
Theme theme = new Theme("Test", "Testing Unlimited");
Theme theme = new Theme("Test", "Testing Unlimited", "n000001");

Home home = new Home();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void testCreateTheme() throws JsonProcessingException, Exception {
describeTheme.withField("active", "Designates the theme currently in use."),
describeTheme.withField("name", "The name of the theme."),
describeTheme.withField("organization", "An organization the theme belongs to."),
describeTheme.withField("organizationId", "An id of the organization the theme belongs to."),
describeTheme.withSubsection("home", "A <<resources-home, Home resource>>."),
describeTheme.withSubsection("header", "A <<resources-header, Header resource>>."),
describeTheme.withSubsection("footer", "A <<resources-header, Footer resource>>."),
Expand All @@ -85,6 +86,7 @@ public void testCreateTheme() throws JsonProcessingException, Exception {
describeTheme.withField("active", "Designates the theme currently in use."),
describeTheme.withField("name", "The name of the theme."),
describeTheme.withField("organization", "An organization the theme belongs to."),
describeTheme.withField("organizationId", "An id of the organization the theme belongs to."),
describeTheme.withSubsection("home", "A <<resources-home, Home resource>>."),
describeTheme.withSubsection("header", "A <<resources-header, Header resource>>."),
describeTheme.withSubsection("footer", "A <<resources-header, Footer resource>>."),
Expand Down Expand Up @@ -115,6 +117,7 @@ public void testUpdateTheme() throws JsonProcessingException, Exception {
describeTheme.withField("active", "Designates the theme currently in use."),
describeTheme.withField("name", "The name of the theme."),
describeTheme.withField("organization", "An organization the theme belongs to."),
describeTheme.withField("organizationId", "An id of the organization the theme belongs to."),
describeTheme.withSubsection("home", "A <<resources-home, Home resource>>."),
describeTheme.withSubsection("header", "A <<resources-header, Header resource>>."),
describeTheme.withSubsection("footer", "A <<resources-header, Footer resource>>."),
Expand All @@ -130,6 +133,7 @@ public void testUpdateTheme() throws JsonProcessingException, Exception {
describeTheme.withField("active", "Designates the theme currently in use."),
describeTheme.withField("name", "The name of the theme."),
describeTheme.withField("organization", "An organization the theme belongs to."),
describeTheme.withField("organizationId", "An id of the organization the theme belongs to."),
describeTheme.withSubsection("home", "A <<resources-home, Home resource>>."),
describeTheme.withSubsection("header", "A <<resources-header, Header resource>>."),
describeTheme.withSubsection("footer", "A <<resources-header, Footer resource>>."),
Expand All @@ -140,24 +144,24 @@ public void testUpdateTheme() throws JsonProcessingException, Exception {
)
)
);
// @formatter:on
// @formatter:on
}

@Test
public void testPatchTheme() throws JsonProcessingException, Exception {
performCreateTheme();
Theme theme = themeRepo.findByName("Test").get();
// @formatter:off
mockMvc.perform(patch("/themes/{id}", theme.getId())
.content("{\"active\": true, \"header\": { \"navbar\": { \"brandText\": \"Hello, Scholars!\"}}}")
.cookie(loginAdmin()))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("active", equalTo(true)))
.andExpect(jsonPath("name", equalTo("Test")))
.andExpect(jsonPath("organization", equalTo("Testing Unlimited")))
.andExpect(jsonPath("header.navbar.brandText", equalTo("Hello, Scholars!")))
.andDo(
mockMvc.perform(patch("/themes/{id}", theme.getId())
.content("{\"active\": true, \"header\": { \"navbar\": { \"brandText\": \"Hello, Scholars!\"}}}")
.cookie(loginAdmin()))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("active", equalTo(true)))
.andExpect(jsonPath("name", equalTo("Test")))
.andExpect(jsonPath("organization", equalTo("Testing Unlimited")))
.andExpect(jsonPath("header.navbar.brandText", equalTo("Hello, Scholars!")))
.andDo(
document(
"themes/patch",
pathParameters(
Expand All @@ -167,6 +171,7 @@ public void testPatchTheme() throws JsonProcessingException, Exception {
describeTheme.withParameter("active", "Designates the theme currently in use.").optional(),
describeTheme.withParameter("name", "The name of the theme.").optional(),
describeTheme.withParameter("organization", "An organization the theme belongs to.").optional(),
describeTheme.withParameter("organizationId", "An id of the organization the theme belongs to.").optional(),
describeTheme.withParameter("home", "A <<resources-home, Home resource>>.").optional(),
describeTheme.withParameter("header", "A <<resources-header, Header resource>>.").optional(),
describeTheme.withParameter("footer", "A <<resources-header, Footer resource>>.").optional(),
Expand All @@ -182,6 +187,7 @@ public void testPatchTheme() throws JsonProcessingException, Exception {
describeTheme.withField("active", "Designates the theme currently in use."),
describeTheme.withField("name", "The name of the theme."),
describeTheme.withField("organization", "An organization the theme belongs to."),
describeTheme.withField("organizationId", "An id of the organization the theme belongs to."),
describeTheme.withSubsection("home", "A <<resources-home, Home resource>>."),
describeTheme.withSubsection("header", "A <<resources-header, Header resource>>."),
describeTheme.withSubsection("footer", "A <<resources-header, Footer resource>>."),
Expand All @@ -192,7 +198,7 @@ public void testPatchTheme() throws JsonProcessingException, Exception {
)
)
);
// @formatter:on
// @formatter:on
}

@Test
Expand All @@ -206,18 +212,18 @@ public void testPatchThemeColors() throws JsonProcessingException, Exception {
colors.add(new Style("--blue", "#007bff"));

// @formatter:off
mockMvc.perform(patch("/themes/" + theme.getId())
.content("{\"colors\": " + objectMapper.writeValueAsString(colors) + "}")
.cookie(loginAdmin()))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("colors[0].key", equalTo("--red")))
.andExpect(jsonPath("colors[0].value", equalTo("#dc3545")))
.andExpect(jsonPath("colors[1].key", equalTo("--green")))
.andExpect(jsonPath("colors[1].value", equalTo("#28a745")))
.andExpect(jsonPath("colors[2].key", equalTo("--blue")))
.andExpect(jsonPath("colors[2].value", equalTo("#007bff")));
// @formatter:on
mockMvc.perform(patch("/themes/" + theme.getId())
.content("{\"colors\": " + objectMapper.writeValueAsString(colors) + "}")
.cookie(loginAdmin()))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("colors[0].key", equalTo("--red")))
.andExpect(jsonPath("colors[0].value", equalTo("#dc3545")))
.andExpect(jsonPath("colors[1].key", equalTo("--green")))
.andExpect(jsonPath("colors[1].value", equalTo("#28a745")))
.andExpect(jsonPath("colors[2].key", equalTo("--blue")))
.andExpect(jsonPath("colors[2].value", equalTo("#007bff")));
// @formatter:on
}

@Test
Expand All @@ -231,18 +237,18 @@ public void testPatchThemeVariants() throws JsonProcessingException, Exception {
variants.add(new Style("--success", "#28a745"));

// @formatter:off
mockMvc.perform(patch("/themes/" + theme.getId())
.content("{\"variants\": " + objectMapper.writeValueAsString(variants) + "}")
.cookie(loginAdmin()))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("variants[0].key", equalTo("--primary")))
.andExpect(jsonPath("variants[0].value", equalTo("#500000")))
.andExpect(jsonPath("variants[1].key", equalTo("--secondary")))
.andExpect(jsonPath("variants[1].value", equalTo("#65a6d1")))
.andExpect(jsonPath("variants[2].key", equalTo("--success")))
.andExpect(jsonPath("variants[2].value", equalTo("#28a745")));
// @formatter:on
mockMvc.perform(patch("/themes/" + theme.getId())
.content("{\"variants\": " + objectMapper.writeValueAsString(variants) + "}")
.cookie(loginAdmin()))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("variants[0].key", equalTo("--primary")))
.andExpect(jsonPath("variants[0].value", equalTo("#500000")))
.andExpect(jsonPath("variants[1].key", equalTo("--secondary")))
.andExpect(jsonPath("variants[1].value", equalTo("#65a6d1")))
.andExpect(jsonPath("variants[2].key", equalTo("--success")))
.andExpect(jsonPath("variants[2].value", equalTo("#28a745")));
// @formatter:on
}

@Test
Expand All @@ -256,33 +262,33 @@ public void testPatchThemeVariables() throws JsonProcessingException, Exception
variables.add(new Style("--navbar-color", "#0000ff"));

// @formatter:off
mockMvc.perform(patch("/themes/" + theme.getId())
.content("{\"variables\": " + objectMapper.writeValueAsString(variables) + "}")
.cookie(loginAdmin()))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("variables[0].key", equalTo("--accent")))
.andExpect(jsonPath("variables[0].value", equalTo("#00ff00")))
.andExpect(jsonPath("variables[1].key", equalTo("--navigation-color")))
.andExpect(jsonPath("variables[1].value", equalTo("#ff0000")))
.andExpect(jsonPath("variables[2].key", equalTo("--navbar-color")))
.andExpect(jsonPath("variables[2].value", equalTo("#0000ff")));
// @formatter:on
mockMvc.perform(patch("/themes/" + theme.getId())
.content("{\"variables\": " + objectMapper.writeValueAsString(variables) + "}")
.cookie(loginAdmin()))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("variables[0].key", equalTo("--accent")))
.andExpect(jsonPath("variables[0].value", equalTo("#00ff00")))
.andExpect(jsonPath("variables[1].key", equalTo("--navigation-color")))
.andExpect(jsonPath("variables[1].value", equalTo("#ff0000")))
.andExpect(jsonPath("variables[2].key", equalTo("--navbar-color")))
.andExpect(jsonPath("variables[2].value", equalTo("#0000ff")));
// @formatter:on
}

@Test
public void testGetTheme() throws JsonProcessingException, Exception {
performCreateTheme();
Theme theme = themeRepo.findByName("Test").get();
// @formatter:off
mockMvc.perform(get("/themes/{id}", theme.getId())
.cookie(loginAdmin()))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("active", equalTo(false)))
.andExpect(jsonPath("name", equalTo("Test")))
.andExpect(jsonPath("organization", equalTo("Testing Unlimited")))
.andDo(
mockMvc.perform(get("/themes/{id}", theme.getId())
.cookie(loginAdmin()))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("active", equalTo(false)))
.andExpect(jsonPath("name", equalTo("Test")))
.andExpect(jsonPath("organization", equalTo("Testing Unlimited")))
.andDo(
document(
"themes/find-by-id",
pathParameters(
Expand All @@ -296,6 +302,7 @@ public void testGetTheme() throws JsonProcessingException, Exception {
describeTheme.withField("active", "Designates the theme currently in use."),
describeTheme.withField("name", "The name of the theme."),
describeTheme.withField("organization", "An organization the theme belongs to."),
describeTheme.withField("organizationId", "An id of the organization the theme belongs to."),
describeTheme.withSubsection("home", "A <<resources-home, Home resource>>."),
describeTheme.withSubsection("header", "A <<resources-header, Header resource>>."),
describeTheme.withSubsection("footer", "A <<resources-header, Footer resource>>."),
Expand All @@ -306,16 +313,16 @@ public void testGetTheme() throws JsonProcessingException, Exception {
)
)
);
// @formatter:on
// @formatter:on
}

@Test
public void testGetThemes() throws JsonProcessingException, Exception {
performCreateTheme();
// @formatter:off
mockMvc.perform(
get("/themes").param("page", "0").param("size", "20").param("sort", "name")
.cookie(loginAdmin()))
mockMvc.perform(
get("/themes").param("page", "0").param("size", "20").param("sort", "name")
.cookie(loginAdmin()))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("page.size", equalTo(20)))
Expand Down Expand Up @@ -392,22 +399,22 @@ public void testGetThemes() throws JsonProcessingException, Exception {
)
)
);
// @formatter:on
// @formatter:on
}

@Test
public void testGetActiveTheme() throws JsonProcessingException, Exception {
performCreateTheme();
performUpdateTheme();
// @formatter:off
mockMvc.perform(get("/themes/search/active"))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("active", equalTo(true)))
.andExpect(jsonPath("name", equalTo("Test")))
.andExpect(jsonPath("organization", equalTo("Testing Limited")))
mockMvc.perform(get("/themes/search/active"))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON_VALUE))
.andExpect(jsonPath("active", equalTo(true)))
.andExpect(jsonPath("name", equalTo("Test")))
.andExpect(jsonPath("organization", equalTo("Testing Limited")))
.andDo(document("themes/active"));
// @formatter:on
// @formatter:on
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public void testDefaultConstructor() {

@Test
public void testBasicConstructor() {
Theme theme = new Theme("Test", "Testing Unlimited");
Theme theme = new Theme("Test", "Testing Unlimited", "n000001");
assertEquals("Test", theme.getName());
assertEquals("Testing Unlimited", theme.getOrganization());
assertEquals("n000001", theme.getOrganizationId());
}

@Test
Expand All @@ -45,10 +46,12 @@ public void testGettersAndSetters() {
theme.setId(1L);
theme.setName("Test");
theme.setOrganization("Testing Unlimited");
theme.setOrganizationId("n000001");

assertEquals(1L, theme.getId(), 1);
assertEquals("Test", theme.getName());
assertEquals("Testing Unlimited", theme.getOrganization());
assertEquals("n000001", theme.getOrganizationId());

Home home = new Home();

Expand Down

0 comments on commit 1339e65

Please sign in to comment.