From 0b41603ffb38c84670a2532122aa64564b105f3b Mon Sep 17 00:00:00 2001 From: Kharec Date: Thu, 2 Apr 2026 17:31:30 +0200 Subject: [PATCH] test: add unit tests --- test/teotipi_test.gleam | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/teotipi_test.gleam diff --git a/test/teotipi_test.gleam b/test/teotipi_test.gleam new file mode 100644 index 0000000..0d706c7 --- /dev/null +++ b/test/teotipi_test.gleam @@ -0,0 +1,65 @@ +import gleam/string +import gleeunit +import gleeunit/should +import teotipi + +pub fn main() -> Nil { + gleeunit.main() +} + +pub fn totp_string_test() { + "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ" + |> teotipi.totp_string + |> should.be_ok + |> string.length + |> should.equal(6) +} + +pub fn totp_string_padding_test() { + "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ" + |> teotipi.totp_string + |> should.be_ok +} + +pub fn totp_string_invalid_secret_test() { + teotipi.totp_string("INVALID!!!") + |> should.be_error +} + +pub fn totp_function_test() { + let code = + "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ" + |> teotipi.totp + |> should.be_ok + + should.be_true(code > 0) + should.be_true(code < 1_000_000) +} + +pub fn totp_invalid_secret_test() { + teotipi.totp("INVALID!!!") + |> should.be_error +} + +pub fn totp_consistency_test() { + let secret = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ" + let result1 = teotipi.totp(secret) + let result2 = teotipi.totp(secret) + + should.equal(result1, result2) +} + +pub fn totp_different_secrets_test() { + let code1 = + "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ" + |> teotipi.totp + |> should.be_ok + + let code2 = + "JBSWY3DPEHPK3PXPJBSWY3DPEHPK3PXP" + |> teotipi.totp + |> should.be_ok + + should.be_true(code1 > 0) + should.be_true(code2 > 0) +}