diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c64dcc9..1b33b67 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] env: CARGO_TERM_COLOR: always @@ -36,4 +36,10 @@ jobs: uses: codecov/codecov-action@v5 with: files: lcov.info - token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/torii-auth-email/src/migrations/mod.rs b/torii-auth-email/src/migrations/mod.rs index 084f318..7e0a1d3 100644 --- a/torii-auth-email/src/migrations/mod.rs +++ b/torii-auth-email/src/migrations/mod.rs @@ -34,3 +34,89 @@ impl PluginMigration for AddPasswordHashColumn { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + + use sqlx::SqlitePool; + + #[tokio::test] + async fn test_migration_up_down_up() -> Result<(), Error> { + let pool = SqlitePool::connect("sqlite::memory:") + .await + .expect("Failed to create test pool"); + + // Create users table first since we're adding a column to it + sqlx::query( + r#" + CREATE TABLE users ( + id TEXT PRIMARY KEY, + email TEXT NOT NULL UNIQUE, + name TEXT, + email_verified_at TIMESTAMP, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP + ) + "#, + ) + .execute(&pool) + .await + .expect("Failed to create users table"); + + let migration = AddPasswordHashColumn; + + // First up migration + migration.up(&pool).await?; + + // Verify column exists + let has_column = sqlx::query( + r#" + SELECT 1 FROM pragma_table_info('users') + WHERE name = 'password_hash' + "#, + ) + .fetch_optional(&pool) + .await?; + assert!( + has_column.is_some(), + "Column should exist after up migration" + ); + + // Down migration + migration.down(&pool).await?; + + // Verify column was removed + let has_column = sqlx::query( + r#" + SELECT 1 FROM pragma_table_info('users') + WHERE name = 'password_hash' + "#, + ) + .fetch_optional(&pool) + .await?; + assert!( + has_column.is_none(), + "Column should not exist after down migration" + ); + + // Second up migration + migration.up(&pool).await?; + + // Verify column exists again + let has_column = sqlx::query( + r#" + SELECT 1 FROM pragma_table_info('users') + WHERE name = 'password_hash' + "#, + ) + .fetch_optional(&pool) + .await?; + assert!( + has_column.is_some(), + "Column should exist after second up migration" + ); + + Ok(()) + } +}