diff --git a/backend/pkg/database/gorm_repository_migrations.go b/backend/pkg/database/gorm_repository_migrations.go index 1f69e01f..db60d0b8 100644 --- a/backend/pkg/database/gorm_repository_migrations.go +++ b/backend/pkg/database/gorm_repository_migrations.go @@ -210,7 +210,7 @@ func (gr *GormRepository) Migrate() error { // set first user to admin // set all other users to user users := []_20240813222836.User{} - results := tx.Order("created_at").Find(&users) + results := tx.Order("created_at ASC").Find(&users) if results.Error != nil { return results.Error } diff --git a/backend/pkg/database/postgres_repository.go b/backend/pkg/database/postgres_repository.go index 44e156e4..09ac5580 100644 --- a/backend/pkg/database/postgres_repository.go +++ b/backend/pkg/database/postgres_repository.go @@ -24,7 +24,6 @@ func newPostgresRepository(appConfig config.Interface, globalLogger logrus.Field database, err := gorm.Open(postgres.Open(dsn), &gorm.Config{ //TODO: figure out how to log database queries again. //logger: logger - TranslateError: true, DisableForeignKeyConstraintWhenMigrating: true, }) diff --git a/backend/pkg/database/sqlite_repository.go b/backend/pkg/database/sqlite_repository.go index 63d427e6..ff463688 100644 --- a/backend/pkg/database/sqlite_repository.go +++ b/backend/pkg/database/sqlite_repository.go @@ -68,7 +68,6 @@ func newSqliteRepository(appConfig config.Interface, globalLogger logrus.FieldLo database, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{ //TODO: figure out how to log database queries again. //logger: logger - TranslateError: true, DisableForeignKeyConstraintWhenMigrating: true, }) diff --git a/frontend/src/app/components/header/header.component.spec.ts b/frontend/src/app/components/header/header.component.spec.ts index 32ac98a1..40653044 100644 --- a/frontend/src/app/components/header/header.component.spec.ts +++ b/frontend/src/app/components/header/header.component.spec.ts @@ -1,29 +1,44 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { HeaderComponent } from './header.component'; -import {HttpClientTestingModule} from '@angular/common/http/testing'; -import {RouterModule} from '@angular/router'; -import {RouterTestingModule} from '@angular/router/testing'; -import {HTTP_CLIENT_TOKEN} from '../../dependency-injection'; -import {HttpClient} from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { RouterModule } from '@angular/router'; +import { RouterTestingModule } from '@angular/router/testing'; import { IconsModule } from 'src/app/icon-module'; +import { HTTP_CLIENT_TOKEN } from '../../dependency-injection'; +import { AuthService } from '../../services/auth.service'; +import { HeaderComponent } from './header.component'; +import { of } from 'rxjs'; +import { UserRegisteredClaims } from '../../models/fasten/user-registered-claims'; describe('HeaderComponent', () => { let component: HeaderComponent; let fixture: ComponentFixture; + let mockedAuthService; beforeEach(async(() => { + mockedAuthService = jasmine.createSpyObj( + 'AuthService', + { + 'getCurrentUser': of(new UserRegisteredClaims()), + 'IsAdmin': of(false) + } + ) TestBed.configureTestingModule({ - imports: [ HttpClientTestingModule, RouterTestingModule, RouterModule, IconsModule ], - declarations: [ HeaderComponent ], + imports: [HttpClientTestingModule, RouterTestingModule, RouterModule, IconsModule], + declarations: [HeaderComponent], providers: [ { provide: HTTP_CLIENT_TOKEN, useClass: HttpClient, }, + { + provide: AuthService, + useValue: mockedAuthService + } ] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/frontend/src/app/models/fasten/user.ts b/frontend/src/app/models/fasten/user.ts index 9dc07a52..52739048 100644 --- a/frontend/src/app/models/fasten/user.ts +++ b/frontend/src/app/models/fasten/user.ts @@ -4,5 +4,5 @@ export class User { username?: string email?: string password?: string - is_admin?: boolean + role?: string } diff --git a/frontend/src/app/pages/user-list/user-list.component.spec.ts b/frontend/src/app/pages/user-list/user-list.component.spec.ts new file mode 100644 index 00000000..a57a7e45 --- /dev/null +++ b/frontend/src/app/pages/user-list/user-list.component.spec.ts @@ -0,0 +1,33 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { RouterTestingModule } from '@angular/router/testing'; +import { of } from 'rxjs'; +import { PipesModule } from '../../pipes/pipes.module'; +import { FastenApiService } from '../../services/fasten-api.service'; +import { UserListComponent } from './user-list.component'; + +describe('UserListComponent', () => { + let component: UserListComponent; + let fixture: ComponentFixture; + let mockedFastenApiService; + + beforeEach(async () => { + mockedFastenApiService = jasmine.createSpyObj('FastenApiService', { 'getAllUsers': of([{}]) }) + await TestBed.configureTestingModule({ + declarations: [UserListComponent], + imports: [PipesModule, RouterTestingModule], + providers: [{ + provide: FastenApiService, + useValue: mockedFastenApiService + }] + }) + .compileComponents(); + fixture = TestBed.createComponent(UserListComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/pages/user-list/user-list.component.ts b/frontend/src/app/pages/user-list/user-list.component.ts index 3bbe8d3b..f3f1dc6d 100644 --- a/frontend/src/app/pages/user-list/user-list.component.ts +++ b/frontend/src/app/pages/user-list/user-list.component.ts @@ -12,7 +12,11 @@ export class UserListComponent implements OnInit { users: User[] = []; loading: boolean = false; - constructor(private fastenApi: FastenApiService, private router: Router, private route: ActivatedRoute) { } + constructor( + private fastenApi: FastenApiService, + private router: Router, + private route: ActivatedRoute + ) { } ngOnInit(): void { this.loadUsers();