Skip to content

Commit

Permalink
Merge branch 'release/0.13.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ogbeche77 committed Mar 16, 2021
2 parents ef071c3 + f4b9cbb commit c787193
Show file tree
Hide file tree
Showing 266 changed files with 7,977 additions and 5,710 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
if: startsWith(github.ref, 'refs/heads/release') || startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/heads/develop')
run: |
echo ${{ secrets.PAT }} | docker login ghcr.io -u airydevci --password-stdin
./scripts/push-images.sh ${{ github.ref }}
./scripts/push-images.sh
- name: Install aws cli
uses: chrislennon/[email protected]
env:
Expand All @@ -67,4 +67,4 @@ jobs:
aws s3 cp bazel-bin/infrastructure/cli/airy_linux_bin s3://airy-core-binaries/develop/linux/amd64/airy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ package-lock.json

# Misc
.DS_Store

# Testing
cypress
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
docs/docs/cli/reference.md
**/*/cli/reference.md
**/*/changelog.md
build/
bazel-*
**/*/.docusaurus
26 changes: 26 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"bracketSpacing": false,
"singleQuote": true,
"jsxBracketSameLine": true,
"semi": true,
"trailingComma": "es5",
"printWidth": 120,
"arrowParens": "avoid",
"endOfLine": "auto",
"overrides": [
{
"files": "*.{ts,tsx}",
"options": {
"parser": "typescript"
}
},
{
"files": "*.md",
"options": {
"singleQuote": false,
"quoteProps": "preserve",
"trailingComma": "none"
}
}
]
}
3 changes: 3 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ alias(

fix_prettier(
name = "fix_prettier",
config = "//:.prettierrc.json",
ignore = "//:.prettierignore",
)

Expand Down Expand Up @@ -100,6 +101,7 @@ java_library(
exports = [
"@maven//:javax_servlet_javax_servlet_api",
"@maven//:javax_validation_validation_api",
"@maven//:org_hibernate_validator_hibernate_validator",
"@maven//:org_springframework_boot_spring_boot",
"@maven//:org_springframework_boot_spring_boot_autoconfigure",
"@maven//:org_springframework_boot_spring_boot_loader",
Expand Down Expand Up @@ -174,6 +176,7 @@ java_library(
exports_files(
[
"package.json",
".eslintrc",
".prettierrc.json",
".prettierignore",
"yarn.lock",
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.0
0.13.0
21 changes: 12 additions & 9 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
# Airy Bazel tools
git_repository(
name = "com_github_airyhq_bazel_tools",
commit = "9cf55cc0a42d68f0198883b04493ce7c7b3113ed",
commit = "b34a57be44e3cdf739e074dde1c3db5b5347cc35",
remote = "https://github.com/airyhq/bazel-tools.git",
shallow_since = "1614958086 +0100",
shallow_since = "1615392891 +0100",
)

load("@com_github_airyhq_bazel_tools//:repositories.bzl", "airy_bazel_tools_dependencies", "airy_jvm_deps")
Expand Down Expand Up @@ -119,10 +119,10 @@ pinned_maven_install()
# This needs to come before any rules_docker usage as it brings its own version of Gazelle
http_archive(
name = "bazel_gazelle",
sha256 = "b85f48fa105c4403326e9525ad2b2cc437babaa6e15a3fc0b1dbab0ab064bc7c",
sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
],
)

Expand All @@ -134,7 +134,10 @@ load("@io_bazel_rules_go//extras:embed_data_deps.bzl", "go_embed_data_dependenci

go_embed_data_dependencies()

go_register_toolchains(nogo = "@//:airy_nogo") # my_nogo is in the top-level BUILD file of this workspace
go_register_toolchains(
nogo = "@//:airy_nogo",
version = "1.16",
) # my_nogo is in the top-level BUILD file of this workspace

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

Expand Down Expand Up @@ -227,9 +230,9 @@ yarn_install(

git_repository(
name = "com_github_atlassian_bazel_tools",
commit = "dc5e715035b6b17f24f1d40a7eac08f8f2ac8a11",
remote = "https://github.com/atlassian/bazel-tools.git",
shallow_since = "1597268988 +1000",
commit = "e45e55f213b6804115eed1b6eb4ffc3bcf7a0cc4",
remote = "https://github.com/ash2k/bazel-tools.git",
shallow_since = "1614900742 +1100",
)

load("@com_github_atlassian_bazel_tools//multirun:deps.bzl", "multirun_dependencies")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ResponseEntity<?> updateChannel(@RequestBody @Valid UpdateChannelRequestPayload
@PostMapping("/channels.chatplugin.connect")
ResponseEntity<?> connect(@RequestBody @Valid ConnectChannelRequestPayload requestPayload) {
final String sourceChannelId = requestPayload.getName();
final String sourceIdentifier = "chat_plugin";
final String sourceIdentifier = "chatplugin";

final String channelId = UUIDv5.fromNamespaceAndName(sourceIdentifier, sourceChannelId).toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ ResponseEntity<?> createTemplate(@RequestBody @Valid CreateTemplateRequestPayloa
final Template template = Template.newBuilder()
.setId(UUID.randomUUID().toString())
.setName(payload.getName())
.setSource(payload.getSource())
.setContent(objectMapper.writeValueAsString(payload.getContent()))
.setVariables(objectMapper.writeValueAsString(payload.getVariables()))
.build();

try {
Expand Down Expand Up @@ -74,12 +74,8 @@ ResponseEntity<?> deleteTemplate(@RequestBody @Valid DeleteTemplateRequestPayloa
@PostMapping("/templates.list")
ResponseEntity<?> listTemplates(@RequestBody @Valid ListTemplatesRequestPayload payload) {
final List<TemplatePayload> response = stores.getTemplates().stream()
.filter(t -> {
if (payload.getName() == null || payload.getName().isEmpty()) {
return true;
}
return t.getName().contains(payload.getName());
})
.filter(t -> t.getSource().equals(payload.getSource()))
.filter(t -> (payload.getName() == null || payload.getName().isEmpty()) || t.getName().contains(payload.getName()))
.map(TemplatePayload::fromTemplate)
.collect(toList());

Expand All @@ -102,8 +98,8 @@ ResponseEntity<?> updateTemplate(@RequestBody @Valid UpdateTemplateRequestPayloa
template.setContent(objectMapper.writeValueAsString(payload.getContent()));
}

if (payload.getVariables() != null) {
template.setVariables(objectMapper.writeValueAsString(payload.getVariables()));
if (payload.getSource() != null) {
template.setSource(payload.getSource());
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class CreateTemplateRequestPayload {
@NotNull
private String name;
@NotNull
private JsonNode content;
@Valid
private String source;
@NotNull
private JsonNode variables;
private JsonNode content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ListTemplatesRequestPayload {
private String name;
@NotNull
private String source;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class UpdateTemplateRequestPayload {
@NotNull
private UUID id;
private String source;
private String name;
private JsonNode content;
private JsonNode variables;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.concurrent.TimeUnit;

import static co.airy.test.Timing.retryOnException;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.not;
Expand Down Expand Up @@ -78,51 +77,91 @@ void beforeEach() throws Exception {
@Test
void canManageTemplates() throws Exception {
final String name = "awesome-template";
final String source = "facebook";
final String content = "{\"blueprint\":\"text\",\"payload\":\"[[salutation]]!\"}";
final String payload = "{\"name\":\"" + name + "\",\"content\":" + content + ",\"variables\": { \"en\": {\"salutation\": \"Hello\"}}}";
final String payload = "{\"name\":\"" + name + "\",\"source\": \"" + source + "\",\"content\":" + content + "}";

final String createTagResponse = webTestHelper.post("/templates.create", payload, "user-id")
final String createTemplateResponse = webTestHelper.post("/templates.create", payload, "user-id")
.andExpect(status().isCreated())
.andReturn()
.getResponse()
.getContentAsString();

final JsonNode jsonNode = objectMapper.readTree(createTagResponse);
final JsonNode jsonNode = objectMapper.readTree(createTemplateResponse);
final String templateId = jsonNode.get("id").textValue();

assertThat(templateId, is(not(nullValue())));

//TODO wait for template to be there
TimeUnit.SECONDS.sleep(5);
retryOnException(() -> webTestHelper.post("/templates.info", "{\"id\":\"" + templateId + "\"}", "user-id")
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(is(templateId)))
.andExpect(jsonPath("$.content.blueprint").value(is("text")))
.andExpect(jsonPath("$.source").value(is(source)))
.andExpect(jsonPath("$.name").value(is(name))), "could not find template");

webTestHelper.post("/templates.info", "{\"id\":\"" + templateId + "\"}", "user-id")
webTestHelper.post("/templates.update", "{\"id\":\"" + templateId + "\", \"name\": \"new-template-name\", \"source\": \"google\", \"content\": " + content + "}", "user-id")
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(is(templateId)))
.andExpect(jsonPath("$.content").value(is(content)))
.andExpect(jsonPath("$.variables.en.salutation").value(is("Hello")))
.andExpect(jsonPath("$.name").value(is(name)));
.andExpect(jsonPath("$.content.blueprint").value(is("text")))
.andExpect(jsonPath("$.source").value(is("google")))
.andExpect(jsonPath("$.name").value(is("new-template-name")));

retryOnException(() -> webTestHelper.post("/templates.info", "{\"id\":\"" + templateId + "\"}", "user-id")
.andExpect(status().isOk())
.andExpect(jsonPath("$.name").value(is("new-template-name"))), "could not update template");

webTestHelper.post("/templates.delete", "{\"id\": \"" + templateId + "\"}", "user-id").andExpect(status().isOk());
}

@Test
void canListTemplates() throws Exception {
final String googleSource = "google";
final String googleContent = "{\"blueprint\":\"text\",\"payload\":\"[[salutation]]!\"}";

webTestHelper.post("/templates.list", "{\"name\":\"" + name.substring(0, 3) + "\"}", "user-id")
for (int i = 0; i < 10; i++) {
final String name = "awesome-template-" + i;
final String payload = "{\"name\":\"" + name + "\",\"source\": \"" + googleSource + "\",\"content\":" + googleContent + "}";

webTestHelper.post("/templates.create", payload, "user-id").andExpect(status().isCreated());
}

final String twilioSource = "twilio.sms";
final String twilioContent = "{\"blueprint\":\"text\",\"payload\":\"[[salutation]]!\"}";
for (int i = 0; i < 5; i++) {
final String name = "awesome-template-" + i;
final String payload = "{\"name\":\"" + name + "\",\"source\": \"" + twilioSource + "\",\"content\":" + twilioContent + "}";

webTestHelper.post("/templates.create", payload, "user-id").andExpect(status().isCreated());
}

retryOnException(() -> webTestHelper.post("/templates.list",
"{\"source\": \"google\"}", "user-id")
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()", is(1)))
.andExpect(jsonPath("$.data[0].id").value(is(templateId)))
.andExpect(jsonPath("$.data[0].name").value(is(name)));
.andExpect(jsonPath("$.data.length()", is(10))), "could not list google templates");

webTestHelper.post("/templates.update", "{\"id\":\"" + templateId + "\", \"name\": \"new-template-name\", \"content\": " + content + "}", "user-id")
retryOnException(() -> webTestHelper.post("/templates.list",
"{\"source\": \"google\", \"name\": \"awesome-template-\"}", "user-id")
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(is(templateId)))
.andExpect(jsonPath("$.content").value(is(content)))
.andExpect(jsonPath("$.variables.en.salutation").value(is("Hello")))
.andExpect(jsonPath("$.name").value(is("new-template-name")));
.andExpect(jsonPath("$.data.length()", is(10))), "could not list google templates by name");

webTestHelper.post("/templates.info", "{\"id\":\"" + templateId + "\"}", "user-id")
retryOnException(() -> webTestHelper.post("/templates.list",
"{\"source\": \"google\", \"name\": \"awesome-template-1\"}", "user-id")
.andExpect(status().isOk())
.andExpect(jsonPath("$.name").value(is("new-template-name")));
.andExpect(jsonPath("$.data.length()", is(1))), "could not list google templates by name");

webTestHelper.post("/templates.list", "{}", "user-id")
retryOnException(() -> webTestHelper.post("/templates.list",
"{\"source\": \"twilio.sms\"}", "user-id")
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()", is(1)));
.andExpect(jsonPath("$.data.length()", is(5))), "could not list twilio templates");

webTestHelper.post("/templates.delete", "{\"id\": \"" + templateId + "\"}", "user-id").andExpect(status().isOk());
retryOnException(() -> webTestHelper.post("/templates.list",
"{\"source\": \"twilio.sms\", \"name\": \"awesome-template-\"}", "user-id")
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()", is(5))), "could not list twilio templates by name");

retryOnException(() -> webTestHelper.post("/templates.list",
"{\"source\": \"twilio.sms\", \"name\": \"awesome-template-1\"}", "user-id")
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()", is(1))), "could not list twilio templates by name");
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package co.airy.core.api.auth.controllers.payload;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SignupRequestPayload {
@NotBlank
private String email;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,26 @@ void canSignupAndLogin() throws Exception {
}

@Test
void canRestPassword() throws Exception {
void canValidateSignup() throws Exception {
final String firstName = "grace";
final String email = "[email protected]";
final String password = "trustno1";

final String signUpRequest = "{\"email\":\"" + email + "\",\"first_name\":\"" + firstName + "\",\"password\":\"" + password + "\"}";

webTestHelper.post("/users.signup", signUpRequest).andExpect(status().isBadRequest());
}

@Test
void canResetPassword() throws Exception {
final String email = "[email protected]";

final String signUpRequest = "{\"email\":\"" + email + "\",\"first_name\":\"something\"," +
"\"last_name\":\"hopper\",\"password\":\"trustno1\"}";

webTestHelper.post("/users.signup", signUpRequest).andExpect(status().isOk());

final String passwordResetRequest = "{\"email\":\"" + email + "\"}";
final String passwordResetRequest = "{\"email\":\"" + email + "\",\"password\":\"trustno1\"}";

doNothing().when(mail).send(Mockito.eq(email), anyString(), anyString());

Expand Down Expand Up @@ -186,7 +197,7 @@ void canChangePassword() throws Exception {
final JsonNode jsonNode = objectMapper.readTree(signupResponse);
final String userId = jsonNode.get("id").textValue();

final String requestPasswordRequest = "{\"email\":\"" + email + "\"}";
final String requestPasswordRequest = "{\"email\":\"" + email + "\", \"password\":\"trustno1\"}";

doNothing().when(mail).send(Mockito.eq(email), anyString(), anyString());

Expand Down
Loading

0 comments on commit c787193

Please sign in to comment.