|
| 1 | +/* |
| 2 | + Copyright 2025 Jose Morales [email protected] |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package com.josdem.vetlog.model |
| 18 | + |
| 19 | +import com.josdem.vetlog.enums.RegistrationCodeStatus |
| 20 | +import org.junit.jupiter.api.Test |
| 21 | +import org.junit.jupiter.api.TestInfo |
| 22 | +import org.slf4j.LoggerFactory |
| 23 | +import java.time.LocalDateTime |
| 24 | +import java.time.temporal.ChronoUnit |
| 25 | +import kotlin.test.assertEquals |
| 26 | +import kotlin.test.assertFalse |
| 27 | +import kotlin.test.assertTrue |
| 28 | + |
| 29 | +internal class RegistrationCodeTest { |
| 30 | + private val registrationCode: RegistrationCode = RegistrationCode() |
| 31 | + |
| 32 | + private val log = LoggerFactory.getLogger(this::class.java) |
| 33 | + |
| 34 | + @Test |
| 35 | + fun `should generate registration code`(testInfo: TestInfo) { |
| 36 | + log.info(testInfo.displayName) |
| 37 | + assertEquals(7, ChronoUnit.DAYS.between(registrationCode.dateCreated, LocalDateTime.now().plusDays(7))) |
| 38 | + assertEquals(36, registrationCode.token.length) |
| 39 | + assertTrue { registrationCode.isValid } |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + fun `should invalidate token`(testInfo: TestInfo) { |
| 44 | + log.info(testInfo.displayName) |
| 45 | + registrationCode.status = RegistrationCodeStatus.INVALID |
| 46 | + assertFalse { registrationCode.isValid } |
| 47 | + } |
| 48 | +} |
0 commit comments