Skip to content

Commit f5b6f6b

Browse files
0xPoeTurbo87
authored andcommitted
test: non-expired tokens are not affected
Signed-off-by: hi-rustin <[email protected]>
1 parent c166f89 commit f5b6f6b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/worker/jobs/expiry_notification.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ mod tests {
135135
.returning(ApiToken::as_returning())
136136
.get_result(&mut conn)?;
137137

138+
// Insert a few tokens that are not set to expire.
139+
let not_expired_offset = EXPIRY_THRESHOLD + 1;
140+
for i in 0..3 {
141+
let token = PlainToken::generate();
142+
diesel::insert_into(api_tokens::table)
143+
.values((
144+
api_tokens::user_id.eq(user.id),
145+
api_tokens::name.eq(format!("test_token{i}")),
146+
api_tokens::token.eq(token.hashed()),
147+
api_tokens::expired_at.eq(now.nullable() + (not_expired_offset).day()),
148+
))
149+
.returning(ApiToken::as_returning())
150+
.get_result(&mut conn)?;
151+
}
152+
138153
// Check that the token is about to expire.
139154
check(&emails, &mut conn)?;
140155

@@ -150,6 +165,14 @@ mod tests {
150165
.first::<ApiToken>(&mut conn)?;
151166
assert!(update_token.expiry_notification_at.is_some());
152167

168+
// Check that the token is not about to expire.
169+
let tokens = api_tokens::table
170+
.filter(api_tokens::revoked.eq(false))
171+
.filter(api_tokens::expiry_notification_at.is_null())
172+
.select(ApiToken::as_select())
173+
.load::<ApiToken>(&mut conn)?;
174+
assert_eq!(tokens.len(), 3);
175+
153176
// Insert a already expired token.
154177
let token = PlainToken::generate();
155178
diesel::insert_into(api_tokens::table)

0 commit comments

Comments
 (0)