public async Task Should_delete_templates() { // STEP 0: Create template. var templateCode1 = Guid.NewGuid().ToString(); var templateCode2 = Guid.NewGuid().ToString(); var templateRequest = new UpsertTemplatesDto { Requests = new List <UpsertTemplateDto> { new UpsertTemplateDto { Code = templateCode1, Formatting = new NotificationFormattingDto { Subject = new LocalizedText { ["en"] = "subject1" } } }, new UpsertTemplateDto { Code = templateCode2, Formatting = new NotificationFormattingDto { Subject = new LocalizedText { ["en"] = "subject2" } } } } }; await _.Client.Templates.PostTemplatesAsync(_.AppId, templateRequest); // STEP 1: Delete template. await _.Client.Templates.DeleteTemplateAsync(_.AppId, templateCode1); // Get templates var templates = await _.Client.Templates.GetTemplatesAsync(_.AppId, take : 100000); var template1 = templates.Items.SingleOrDefault(x => x.Code == templateCode1); var template2 = templates.Items.SingleOrDefault(x => x.Code == templateCode2); Assert.Null(template1); Assert.NotNull(template2); }
public async Task <IActionResult> PostTemplates(string appId, [FromBody] UpsertTemplatesDto request) { var response = new List <TemplateDto>(); foreach (var dto in request.Requests.OrEmpty().NotNull()) { var update = dto.ToUpdate(); var template = await templateStore.UpsertAsync(appId, dto.Code, update, HttpContext.RequestAborted); response.Add(TemplateDto.FromDomainObject(template)); } return(Ok(response)); }
public async Task Should_create_templates() { // STEP 0: Create template. var templateCode1 = Guid.NewGuid().ToString(); var templateCode2 = Guid.NewGuid().ToString(); var templateRequest = new UpsertTemplatesDto { Requests = new List <UpsertTemplateDto> { new UpsertTemplateDto { Code = templateCode1, Formatting = new NotificationFormattingDto { Subject = new LocalizedText { ["en"] = "subject1_0" } } }, new UpsertTemplateDto { Code = templateCode2, Formatting = new NotificationFormattingDto { Subject = new LocalizedText { ["en"] = "subject2_0" } } } } }; var templates = await _.Client.Templates.PostTemplatesAsync(_.AppId, templateRequest); Assert.Equal(2, templates.Count); var template1 = templates.ElementAt(0); var template2 = templates.ElementAt(1); Assert.Equal(templateCode1, template1.Code); Assert.Equal(templateCode2, template2.Code); Assert.Equal("subject1_0", template1.Formatting.Subject["en"]); Assert.Equal("subject2_0", template2.Formatting.Subject["en"]); }
public async Task Should_send_template_formatted_notifications() { var subjectId = Guid.NewGuid().ToString(); // STEP 0: Create user. var userRequest = new UpsertUsersDto { Requests = new List <UpsertUserDto> { new UpsertUserDto() } }; var users_0 = await _.Client.Users.PostUsersAsync(_.AppId, userRequest); var user_0 = users_0.First(); // STEP 1: Create template. var templateCode = Guid.NewGuid().ToString(); var templateRequest = new UpsertTemplatesDto { Requests = new List <UpsertTemplateDto> { new UpsertTemplateDto { Code = templateCode, Formatting = new NotificationFormattingDto { Subject = new LocalizedText { ["en"] = subjectId } } } } }; await _.Client.Templates.PostTemplatesAsync(_.AppId, templateRequest); // STEP 2: Send Notification var publishRequest = new PublishManyDto { Requests = new List <PublishDto> { new PublishDto { Topic = $"users/{user_0.Id}", TemplateCode = templateCode } } }; await _.Client.Events.PostEventsAsync(_.AppId, publishRequest); // Test that notification has been created. var notifications = await _.Client.Notifications.WaitForNotificationsAsync(_.AppId, user_0.Id, null, TimeSpan.FromSeconds(30)); Assert.Contains(notifications, x => x.Subject == subjectId); // Test that user notifications have been created. var userNotifications = await _.Notifo.CreateUserClient(user_0).Notifications.WaitForMyNotificationsAsyn(null, TimeSpan.FromSeconds(30)); Assert.Contains(userNotifications, x => x.Subject == subjectId); }