Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(notifications): make created_at/updated_at outbound timestamp required (#2479)

gbirmane19c53593234
diff --git a/js/app/packages/notifications/tests/notification-preview.test.ts b/js/app/packages/notifications/tests/notification-preview.test.ts
index c1f9d79440..9804c15f0c 100644
--- a/js/app/packages/notifications/tests/notification-preview.test.ts
+++ b/js/app/packages/notifications/tests/notification-preview.test.ts
@@ -10,7 +10,7 @@ function createEmailNotification(
entity_id: 'thread-1',
entity_type: 'email_thread',
created_at: new Date().toISOString(),
- updated_at: null,
+ updated_at: new Date().toISOString(),
viewed_at: null,
deleted_at: null,
done: false,
diff --git a/js/app/packages/notifications/tests/notification-stacking.test.ts b/js/app/packages/notifications/tests/notification-stacking.test.ts
index c01ef69037..62e94b4587 100644
--- a/js/app/packages/notifications/tests/notification-stacking.test.ts
+++ b/js/app/packages/notifications/tests/notification-stacking.test.ts
@@ -19,7 +19,7 @@ function createBaseNotification(
entity_id: 'channel-1',
entity_type: 'channel',
created_at: new Date(createdAt).toISOString(),
- updated_at: null,
+ updated_at: new Date(createdAt).toISOString(),
viewed_at: null,
deleted_at: null,
done: false,
diff --git a/js/app/packages/queries/notification/tests/user-notifications.test.tsx b/js/app/packages/queries/notification/tests/user-notifications.test.tsx
index d823cef11b..37a17b2f62 100644
--- a/js/app/packages/queries/notification/tests/user-notifications.test.tsx
+++ b/js/app/packages/queries/notification/tests/user-notifications.test.tsx
@@ -63,7 +63,7 @@ function createMockNotification(
entity_id: 'entity-1',
entity_type: 'document',
created_at: new Date().toISOString(),
- updated_at: null,
+ updated_at: new Date().toISOString(),
viewed_at: null,
deleted_at: null,
done: false,
@@ -404,7 +404,7 @@ describe('optimisticInsertNotification', () => {
seedQueryCache([createMockNotificationPage([])]);
const notificationWithoutCreatedAt = createMockNotification({
- created_at: null,
+ created_at: undefined,
});
optimisticInsertNotification(notificationWithoutCreatedAt);
diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/apiUserNotificationAllOf.ts b/js/app/packages/service-clients/service-notification/generated/schemas/apiUserNotificationAllOf.ts
index 5c9f4c1e55..4f39cca1ef 100644
--- a/js/app/packages/service-clients/service-notification/generated/schemas/apiUserNotificationAllOf.ts
+++ b/js/app/packages/service-clients/service-notification/generated/schemas/apiUserNotificationAllOf.ts
@@ -4,16 +4,14 @@
* notification_service
* OpenAPI spec version: 0.1.0
*/
-import type { ApiUserNotificationAllOfCreatedAt } from './apiUserNotificationAllOfCreatedAt';
import type { ApiUserNotificationAllOfDeletedAt } from './apiUserNotificationAllOfDeletedAt';
import type { ApiUserNotificationAllOfSenderId } from './apiUserNotificationAllOfSenderId';
-import type { ApiUserNotificationAllOfUpdatedAt } from './apiUserNotificationAllOfUpdatedAt';
import type { ApiUserNotificationAllOfViewedAt } from './apiUserNotificationAllOfViewedAt';
import type { NotifEvent } from './notifEvent';
export type ApiUserNotificationAllOf = {
/** When the notification was created. */
- created_at?: ApiUserNotificationAllOfCreatedAt;
+ created_at: string;
/** When the notification was deleted. */
deleted_at?: ApiUserNotificationAllOfDeletedAt;
/** Whether the notification is marked as done. */
@@ -32,7 +30,7 @@ TODO make this a new type */
/** Whether the notification has been sent. */
sent: boolean;
/** When the notification was last updated. */
- updated_at?: ApiUserNotificationAllOfUpdatedAt;
+ updated_at: string;
/** When the notification was viewed/seen. */
viewed_at?: ApiUserNotificationAllOfViewedAt;
};
diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/apiUserNotificationAllOfCreatedAt.ts b/js/app/packages/service-clients/service-notification/generated/schemas/apiUserNotificationAllOfCreatedAt.ts
deleted file mode 100644
index 1f0670268f..0000000000
--- a/js/app/packages/service-clients/service-notification/generated/schemas/apiUserNotificationAllOfCreatedAt.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * Generated by orval v7.13.0 🍺
- * Do not edit manually.
- * notification_service
- * OpenAPI spec version: 0.1.0
- */
-
-/**
- * When the notification was created.
- */
-export type ApiUserNotificationAllOfCreatedAt = string | null;
diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/apiUserNotificationAllOfUpdatedAt.ts b/js/app/packages/service-clients/service-notification/generated/schemas/apiUserNotificationAllOfUpdatedAt.ts
deleted file mode 100644
index ac65670963..0000000000
--- a/js/app/packages/service-clients/service-notification/generated/schemas/apiUserNotificationAllOfUpdatedAt.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * Generated by orval v7.13.0 🍺
- * Do not edit manually.
- * notification_service
- * OpenAPI spec version: 0.1.0
- */
-
-/**
- * When the notification was last updated.
- */
-export type ApiUserNotificationAllOfUpdatedAt = string | null;
diff --git a/js/app/packages/service-clients/service-notification/generated/schemas/index.ts b/js/app/packages/service-clients/service-notification/generated/schemas/index.ts
index 939251e0a1..83f78afa14 100644
--- a/js/app/packages/service-clients/service-notification/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-notification/generated/schemas/index.ts
@@ -8,10 +8,8 @@
export * from './aiResponseMetadata';
export * from './apiUserNotification';
export * from './apiUserNotificationAllOf';
-export * from './apiUserNotificationAllOfCreatedAt';
export * from './apiUserNotificationAllOfDeletedAt';
export * from './apiUserNotificationAllOfSenderId';
-export * from './apiUserNotificationAllOfUpdatedAt';
export * from './apiUserNotificationAllOfViewedAt';
export * from './bulkGetByEventItemIdsRequest';
export * from './bulkGetTypedNotificationsByEventItemIdsParams';
diff --git a/js/app/packages/service-clients/service-notification/openapi.json b/js/app/packages/service-clients/service-notification/openapi.json
index da807b4d98..61b266aa68 100644
--- a/js/app/packages/service-clients/service-notification/openapi.json
+++ b/js/app/packages/service-clients/service-notification/openapi.json
@@ -1030,11 +1030,13 @@
"notification_event_type",
"sent",
"done",
+ "created_at",
+ "updated_at",
"notification_metadata"
],
"properties": {
"created_at": {
- "type": ["string", "null"],
+ "type": "string",
"format": "date-time",
"description": "When the notification was created."
},
@@ -1073,7 +1075,7 @@
"description": "Whether the notification has been sent."
},
"updated_at": {
- "type": ["string", "null"],
+ "type": "string",
"format": "date-time",
"description": "When the notification was last updated."
},
diff --git a/rust/cloud-storage/email_formatting/src/lib.rs b/rust/cloud-storage/email_formatting/src/lib.rs
index 2312b85215..f7cfb0c67a 100644
--- a/rust/cloud-storage/email_formatting/src/lib.rs
+++ b/rust/cloud-storage/email_formatting/src/lib.rs
@@ -41,7 +41,7 @@ impl NotifPreview {
.format_title(v.sender_id.as_ref().map(CowLike::copied))?;
let body = v.notification_metadata.format_body(v.sender_id)?;
Ok(NotifPreview {
- created_at: v.created_at.unwrap_or(Utc::now()),
+ created_at: v.created_at,
title,
body,
})
diff --git a/rust/cloud-storage/notification/.sqlx/query-b6cda5fd5ec775474b301aa8a7376ff2dfd8c5812db1b6d493cbb355685907f2.json b/rust/cloud-storage/notification/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json
similarity index 65%
rename from rust/cloud-storage/notification/.sqlx/query-b6cda5fd5ec775474b301aa8a7376ff2dfd8c5812db1b6d493cbb355685907f2.json
rename to rust/cloud-storage/notification/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json
index 0b09fbeec2..b17b203167 100644
--- a/rust/cloud-storage/notification/.sqlx/query-b6cda5fd5ec775474b301aa8a7376ff2dfd8c5812db1b6d493cbb355685907f2.json
+++ b/rust/cloud-storage/notification/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz,\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as updated_at,\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND n.event_item_id = ANY($2)\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($4::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($4, $5))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $3\n ",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND n.event_item_id = ANY($2)\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($4::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($4, $5))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $3\n ",
"describe": {
"columns": [
{
@@ -35,7 +35,7 @@
},
{
"ordinal": 6,
- "name": "created_at",
+ "name": "created_at!",
"type_info": "Timestamptz"
},
{
@@ -45,7 +45,7 @@
},
{
"ordinal": 8,
- "name": "updated_at",
+ "name": "updated_at!",
"type_info": "Timestamptz"
},
{
@@ -94,5 +94,5 @@
true
]
},
- "hash": "b6cda5fd5ec775474b301aa8a7376ff2dfd8c5812db1b6d493cbb355685907f2"
+ "hash": "317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e"
}
diff --git a/rust/cloud-storage/notification/.sqlx/query-e231e279615526b33206979b400328d23be40ef9da49697ef6b75cdfcd69caad.json b/rust/cloud-storage/notification/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json
similarity index 70%
rename from rust/cloud-storage/notification/.sqlx/query-e231e279615526b33206979b400328d23be40ef9da49697ef6b75cdfcd69caad.json
rename to rust/cloud-storage/notification/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json
index b36882b3ae..3fdea7e232 100644
--- a/rust/cloud-storage/notification/.sqlx/query-e231e279615526b33206979b400328d23be40ef9da49697ef6b75cdfcd69caad.json
+++ b/rust/cloud-storage/notification/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz,\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as updated_at,\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.notification_id = $2\n AND un.deleted_at IS NULL\n LIMIT 1\n ",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.notification_id = $2\n AND un.deleted_at IS NULL\n LIMIT 1\n ",
"describe": {
"columns": [
{
@@ -35,7 +35,7 @@
},
{
"ordinal": 6,
- "name": "created_at",
+ "name": "created_at!",
"type_info": "Timestamptz"
},
{
@@ -45,7 +45,7 @@
},
{
"ordinal": 8,
- "name": "updated_at",
+ "name": "updated_at!",
"type_info": "Timestamptz"
},
{
@@ -91,5 +91,5 @@
true
]
},
- "hash": "e231e279615526b33206979b400328d23be40ef9da49697ef6b75cdfcd69caad"
+ "hash": "48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4"
}
diff --git a/rust/cloud-storage/notification/.sqlx/query-7cd8368263b84e0dd25d0e7d1ae40b68d3cf69baaf036d2a17bf7d06176f8a53.json b/rust/cloud-storage/notification/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json
similarity index 66%
rename from rust/cloud-storage/notification/.sqlx/query-7cd8368263b84e0dd25d0e7d1ae40b68d3cf69baaf036d2a17bf7d06176f8a53.json
rename to rust/cloud-storage/notification/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json
index 215280eac8..f3780614e0 100644
--- a/rust/cloud-storage/notification/.sqlx/query-7cd8368263b84e0dd25d0e7d1ae40b68d3cf69baaf036d2a17bf7d06176f8a53.json
+++ b/rust/cloud-storage/notification/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz,\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as updated_at,\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($3::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($3, $4))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $2\n ",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($3::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($3, $4))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $2\n ",
"describe": {
"columns": [
{
@@ -35,7 +35,7 @@
},
{
"ordinal": 6,
- "name": "created_at",
+ "name": "created_at!",
"type_info": "Timestamptz"
},
{
@@ -45,7 +45,7 @@
},
{
"ordinal": 8,
- "name": "updated_at",
+ "name": "updated_at!",
"type_info": "Timestamptz"
},
{
@@ -93,5 +93,5 @@
true
]
},
- "hash": "7cd8368263b84e0dd25d0e7d1ae40b68d3cf69baaf036d2a17bf7d06176f8a53"
+ "hash": "d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac"
}
diff --git a/rust/cloud-storage/notification/src/domain/models.rs b/rust/cloud-storage/notification/src/domain/models.rs
index 3741ce7034..0785b3a058 100644
--- a/rust/cloud-storage/notification/src/domain/models.rs
+++ b/rust/cloud-storage/notification/src/domain/models.rs
@@ -56,11 +56,11 @@ pub struct UserNotificationRow<T> {
/// Whether the notification is marked as done.
pub done: bool,
/// When the notification was created.
- pub created_at: Option<DateTime<Utc>>,
+ pub created_at: DateTime<Utc>,
/// When the notification was viewed/seen.
pub viewed_at: Option<DateTime<Utc>>,
/// When the notification was last updated.
- pub updated_at: Option<DateTime<Utc>>,
+ pub updated_at: DateTime<Utc>,
/// When the notification was deleted.
pub deleted_at: Option<DateTime<Utc>>,
/// Deserialized notification metadata.
@@ -240,7 +240,7 @@ impl<T> Identify for UserNotificationRow<T> {
impl<T> SortOn<CreatedAt> for UserNotificationRow<T> {
fn sort_on(sort: CreatedAt) -> impl FnMut(&Self) -> CursorVal<CreatedAt> {
move |v| {
- let last_val = v.created_at.unwrap_or(DateTime::UNIX_EPOCH);
+ let last_val = v.created_at;
CursorVal {
sort_type: sort,
last_val,
diff --git a/rust/cloud-storage/notification/src/domain/models/email_notification_digest/test.rs b/rust/cloud-storage/notification/src/domain/models/email_notification_digest/test.rs
index d9e3b0cd80..0602ef7850 100644
--- a/rust/cloud-storage/notification/src/domain/models/email_notification_digest/test.rs
+++ b/rust/cloud-storage/notification/src/domain/models/email_notification_digest/test.rs
@@ -2,6 +2,7 @@
use super::*;
use crate::domain::models::{Notification, UserNotificationRow};
+use chrono::Utc;
use macro_user_id::user_id::MacroUserIdStr;
use model_entity::EntityType;
use rootcause::Report;
@@ -226,9 +227,9 @@ fn create_test_notification_row<T: Notification>(metadata: T) -> UserNotificatio
entity: EntityType::Document.with_entity_str("doc_123"),
sent: false,
done: false,
- created_at: None,
+ created_at: Utc::now(),
viewed_at: None,
- updated_at: None,
+ updated_at: Utc::now(),
deleted_at: None,
notification_metadata: Arc::new(metadata),
sender_id: None,
diff --git a/rust/cloud-storage/notification/src/domain/models/queue_message.rs b/rust/cloud-storage/notification/src/domain/models/queue_message.rs
index b6d575da6f..3760077c44 100644
--- a/rust/cloud-storage/notification/src/domain/models/queue_message.rs
+++ b/rust/cloud-storage/notification/src/domain/models/queue_message.rs
@@ -128,11 +128,11 @@ pub struct ConnGatewayInnerNotif<T> {
/// Whether the notification is marked as done.
pub done: bool,
/// When the notification was created.
- pub created_at: Option<DateTime<Utc>>,
+ pub created_at: DateTime<Utc>,
/// When the notification was viewed/seen.
pub viewed_at: Option<DateTime<Utc>>,
/// When the notification was last updated.
- pub updated_at: Option<DateTime<Utc>>,
+ pub updated_at: DateTime<Utc>,
/// When the notification was deleted.
pub deleted_at: Option<DateTime<Utc>>,
/// Deserialized notification metadata.
@@ -169,9 +169,9 @@ impl<'a, T: Clone> ConnGatewayNotification<'a, T> {
entity: req.req.notification_entity.clone().into_owned(),
sent: true,
done: false,
- created_at: None,
+ created_at: Utc::now(),
viewed_at: None,
- updated_at: None,
+ updated_at: Utc::now(),
deleted_at: None,
notification_metadata: req.req.notification.clone(),
sender_id: req.req.sender_id.as_ref().map(|x| x.clone().into_owned()),
@@ -237,11 +237,7 @@ pub(crate) enum NotificationChannel<'a, T, U> {
}
impl<'a, T, U> NotificationChannel<'a, T, U> {
- fn with_timestamps(
- self,
- created_at: Option<DateTime<Utc>>,
- updated_at: Option<DateTime<Utc>>,
- ) -> Self {
+ fn with_timestamps(self, created_at: DateTime<Utc>, updated_at: DateTime<Utc>) -> Self {
match self {
NotificationChannel::Ios(apnstargets) => NotificationChannel::Ios(apnstargets),
NotificationChannel::Email(email_notification) => {
@@ -321,8 +317,8 @@ impl<'a, T, U> QueueMessage<'a, T, U> {
pub(crate) fn with_timestamps(
self,
- created_at: Option<DateTime<Utc>>,
- updated_at: Option<DateTime<Utc>>,
+ created_at: DateTime<Utc>,
+ updated_at: DateTime<Utc>,
) -> Self {
let QueueMessage {
message_type,
diff --git a/rust/cloud-storage/notification/src/domain/service/ingress.rs b/rust/cloud-storage/notification/src/domain/service/ingress.rs
index 440c70b070..97ef8a2450 100644
--- a/rust/cloud-storage/notification/src/domain/service/ingress.rs
+++ b/rust/cloud-storage/notification/src/domain/service/ingress.rs
@@ -233,7 +233,11 @@ where
};
// get the timestamp info back out of the db created values
- let timestamps = n.first().map(|n| (n.created_at, n.updated_at));
+ let first = n
+ .first()
+ .ok_or_else(|| rootcause::report!("create_notification returned empty Vec"))
+ .context(SendNotificationError::Other)?;
+ let (created_at, updated_at) = (first.created_at, first.updated_at);
let results = join_all(
n.into_iter()
@@ -245,12 +249,7 @@ where
.publish(
queue_messages
.with_state_decisions(results)
- .map(|msg| {
- msg.with_timestamps(
- timestamps.and_then(|v| v.0),
- timestamps.and_then(|v| v.1),
- )
- })
+ .map(|msg| msg.with_timestamps(created_at, updated_at))
.collect(),
)
.await
diff --git a/rust/cloud-storage/notification/src/domain/service/test.rs b/rust/cloud-storage/notification/src/domain/service/test.rs
index 2cdbf39bcf..e64b9d5c53 100644
--- a/rust/cloud-storage/notification/src/domain/service/test.rs
+++ b/rust/cloud-storage/notification/src/domain/service/test.rs
@@ -24,6 +24,7 @@ use crate::domain::service::{
NotificationEgressService, NotificationIngress, NotificationIngressService, NotificationReader,
NotificationReaderService, PlatformArnConfig,
};
+use chrono::Utc;
use macro_user_id::cowlike::CowLike;
use macro_user_id::user_id::MacroUserIdStr;
use model_entity::EntityType;
@@ -212,9 +213,9 @@ impl NotificationRepository for MockRepository {
entity: entity.clone(),
sent: false,
done: false,
- created_at: None,
+ created_at: Utc::now(),
viewed_at: None,
- updated_at: None,
+ updated_at: Utc::now(),
deleted_at: None,
notification_metadata: notification_metadata.clone(),
sender_id: sender_id.clone(),
@@ -1287,9 +1288,9 @@ fn create_mock_notif<T: Notification>(meta: T) -> ConnGatewayInnerNotif<T> {
entity: EntityType::Document.with_entity_str("testing"),
sent: false,
done: false,
- created_at: None,
+ created_at: Utc::now(),
viewed_at: None,
- updated_at: None,
+ updated_at: Utc::now(),
deleted_at: None,
notification_metadata: TaggedContent::new(meta),
sender_id: None,
@@ -1820,9 +1821,9 @@ async fn test_poll_email_digests_sends_email_for_ready_batch() {
entity: EntityType::Document.with_entity_str("doc-1"),
sent: false,
done: false,
- created_at: None,
+ created_at: Utc::now(),
viewed_at: None,
- updated_at: None,
+ updated_at: Utc::now(),
deleted_at: None,
notification_metadata: serde_json::to_value(TestNotification {
message: "hello from digest".to_string(),
@@ -2253,9 +2254,9 @@ async fn test_poll_email_digests_skips_publish_when_user_disabled_type() {
entity: EntityType::Document.with_entity_str("doc-1"),
sent: false,
done: false,
- created_at: None,
+ created_at: Utc::now(),
viewed_at: None,
- updated_at: None,
+ updated_at: Utc::now(),
deleted_at: None,
notification_metadata: serde_json::to_value(TestNotification {
message: "hello from digest".to_string(),
@@ -2314,9 +2315,9 @@ async fn test_poll_email_digests_publishes_when_user_has_not_disabled_type() {
entity: EntityType::Document.with_entity_str("doc-1"),
sent: false,
done: false,
- created_at: None,
+ created_at: Utc::now(),
viewed_at: None,
- updated_at: None,
+ updated_at: Utc::now(),
deleted_at: None,
notification_metadata: serde_json::to_value(TestNotification {
message: "hello from digest".to_string(),
diff --git a/rust/cloud-storage/notification/src/inbound/ai_tool/mod.rs b/rust/cloud-storage/notification/src/inbound/ai_tool/mod.rs
index bdd8ca50a1..9345f9c3c0 100644
--- a/rust/cloud-storage/notification/src/inbound/ai_tool/mod.rs
+++ b/rust/cloud-storage/notification/src/inbound/ai_tool/mod.rs
@@ -87,7 +87,7 @@ pub struct NotificationItem {
/// Whether the notification is marked as done.
pub done: bool,
/// When the notification was created (ISO 8601).
- pub created_at: Option<String>,
+ pub created_at: String,
/// The notification metadata/payload.
pub metadata: serde_json::Value,
/// The user ID of the sender, if any.
@@ -103,7 +103,7 @@ impl From<UserNotificationRow<serde_json::Value>> for NotificationItem {
entity_id: row.entity.entity_id.into_owned(),
seen: row.viewed_at.is_some(),
done: row.done,
- created_at: row.created_at.map(|t| t.to_rfc3339()),
+ created_at: row.created_at.to_rfc3339(),
metadata: row.notification_metadata,
sender_id: row.sender_id.map(|s| (*s).as_ref().to_owned()),
}
diff --git a/rust/cloud-storage/notification/src/outbound/digest_batcher/test.rs b/rust/cloud-storage/notification/src/outbound/digest_batcher/test.rs
index f0a27655a0..0cc8f4eaef 100644
--- a/rust/cloud-storage/notification/src/outbound/digest_batcher/test.rs
+++ b/rust/cloud-storage/notification/src/outbound/digest_batcher/test.rs
@@ -60,9 +60,9 @@ fn create_test_notification(
entity: EntityType::Document.with_entity_string(Uuid::new_v4().to_string()),
sent: false,
done: false,
- created_at: Some(Utc::now()),
+ created_at: Utc::now(),
viewed_at: None,
- updated_at: Some(Utc::now()),
+ updated_at: Utc::now(),
deleted_at: None,
notification_metadata: serde_json::to_value(TaggedContent::new(notification))
.expect("serialize cannot fail"),
@@ -87,9 +87,9 @@ fn create_raw_test_notification(
entity: EntityType::Document.with_entity_string(Uuid::new_v4().to_string()),
sent: false,
done: false,
- created_at: Some(Utc::now()),
+ created_at: Utc::now(),
viewed_at: None,
- updated_at: Some(Utc::now()),
+ updated_at: Utc::now(),
deleted_at: None,
notification_metadata: serde_json::to_value(notification).expect("serialize cannot fail"),
sender_id: None,
diff --git a/rust/cloud-storage/notification/src/outbound/repository.rs b/rust/cloud-storage/notification/src/outbound/repository.rs
index 0cbfe977a2..77ac59de13 100644
--- a/rust/cloud-storage/notification/src/outbound/repository.rs
+++ b/rust/cloud-storage/notification/src/outbound/repository.rs
@@ -364,9 +364,9 @@ impl NotificationDbOps for PgPool {
entity: entity.clone(),
sent: false,
done: false,
- created_at: Some(created_at),
+ created_at,
viewed_at: None,
- updated_at: Some(created_at),
+ updated_at: created_at,
deleted_at: None,
notification_metadata: n.clone(),
sender_id: sender_id.clone(),
@@ -486,9 +486,9 @@ impl NotificationDbOps for PgPool {
n.event_item_type,
un.sent,
un.done,
- un.created_at::timestamptz,
+ un.created_at::timestamptz as "created_at!",
un.seen_at::timestamptz as viewed_at,
- un.created_at::timestamptz as updated_at,
+ un.created_at::timestamptz as "updated_at!",
un.deleted_at::timestamptz,
n.metadata as "notification_metadata: serde_json::Value",
n.notification_event_type as notification_event_type,
@@ -583,9 +583,9 @@ impl NotificationDbOps for PgPool {
n.event_item_type,
un.sent,
un.done,
- un.created_at::timestamptz,
+ un.created_at::timestamptz as "created_at!",
un.seen_at::timestamptz as viewed_at,
- un.created_at::timestamptz as updated_at,
+ un.created_at::timestamptz as "updated_at!",
un.deleted_at::timestamptz,
n.metadata as "notification_metadata: serde_json::Value",
n.notification_event_type as notification_event_type,
@@ -672,9 +672,9 @@ impl NotificationDbOps for PgPool {
n.event_item_type,
un.sent,
un.done,
- un.created_at::timestamptz,
+ un.created_at::timestamptz as "created_at!",
un.seen_at::timestamptz as viewed_at,
- un.created_at::timestamptz as updated_at,
+ un.created_at::timestamptz as "updated_at!",
un.deleted_at::timestamptz,
n.metadata as "notification_metadata: serde_json::Value",
n.notification_event_type as notification_event_type,
diff --git a/rust/cloud-storage/notification/src/outbound/repository/test.rs b/rust/cloud-storage/notification/src/outbound/repository/test.rs
index dd6b29224f..22215367ab 100644
--- a/rust/cloud-storage/notification/src/outbound/repository/test.rs
+++ b/rust/cloud-storage/notification/src/outbound/repository/test.rs
@@ -175,8 +175,6 @@ async fn test_create_notification_returns_timestamps(pool: Pool<Postgres>) {
assert_eq!(rows.len(), 1);
let row = &rows[0];
- assert!(row.created_at.is_some(), "created_at should be set");
- assert!(row.updated_at.is_some(), "updated_at should be set");
assert_eq!(row.created_at, row.updated_at);
}
diff --git a/rust/cloud-storage/notification_service/src/api/user_notification.rs b/rust/cloud-storage/notification_service/src/api/user_notification.rs
index 8d84c0c3c7..f39bb7922b 100644
--- a/rust/cloud-storage/notification_service/src/api/user_notification.rs
+++ b/rust/cloud-storage/notification_service/src/api/user_notification.rs
@@ -60,11 +60,11 @@ pub struct ApiUserNotification {
/// Whether the notification is marked as done.
pub done: bool,
/// When the notification was created.
- pub created_at: Option<DateTime<Utc>>,
+ pub created_at: DateTime<Utc>,
/// When the notification was viewed/seen.
pub viewed_at: Option<DateTime<Utc>>,
/// When the notification was last updated.
- pub updated_at: Option<DateTime<Utc>>,
+ pub updated_at: DateTime<Utc>,
/// When the notification was deleted.
pub deleted_at: Option<DateTime<Utc>>,
/// Deserialized notification metadata.
diff --git a/rust/cloud-storage/notification_service/src/api/user_notification/test.rs b/rust/cloud-storage/notification_service/src/api/user_notification/test.rs
index e0d0293d8e..a1797d3251 100644
--- a/rust/cloud-storage/notification_service/src/api/user_notification/test.rs
+++ b/rust/cloud-storage/notification_service/src/api/user_notification/test.rs
@@ -1,4 +1,5 @@
use super::*;
+use chrono::Utc;
use macro_user_id::cowlike::CowLike;
use macro_user_id::user_id::MacroUserIdStr;
use model_entity::EntityType;
@@ -18,9 +19,9 @@ fn make_row(
entity: EntityType::Document.with_entity_string("entity-1".to_string()),
sent: true,
done: false,
- created_at: None,
+ created_at: Utc::now(),
viewed_at: None,
- updated_at: None,
+ updated_at: Utc::now(),
deleted_at: None,
notification_metadata: metadata,
sender_id: Some(
@@ -286,9 +287,9 @@ fn api_user_notification_and_conn_gateway_inner_notif_metadata_serialize_identic
entity: entity.clone(),
sent: true,
done: false,
- created_at: Some(created_at),
+ created_at,
viewed_at: None,
- updated_at: None,
+ updated_at: created_at,
deleted_at: None,
notification_metadata: NotifEvent::ChannelMention(notif_metadata.clone()),
sender_id: Some(
@@ -305,9 +306,9 @@ fn api_user_notification_and_conn_gateway_inner_notif_metadata_serialize_identic
entity,
sent: true,
done: false,
- created_at: Some(created_at),
+ created_at,
viewed_at: None,
- updated_at: None,
+ updated_at: created_at,
deleted_at: None,
notification_metadata: TaggedContent::new(notif_metadata),
sender_id: Some(