Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dwradcliffe committed Aug 27, 2024
1 parent 74727ba commit 8eb613b
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 14 deletions.
2 changes: 1 addition & 1 deletion backend/pkg/database/gorm_repository_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion backend/pkg/database/postgres_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
1 change: 0 additions & 1 deletion backend/pkg/database/sqlite_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
33 changes: 24 additions & 9 deletions frontend/src/app/components/header/header.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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<HeaderComponent>;
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(() => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/models/fasten/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export class User {
username?: string
email?: string
password?: string
is_admin?: boolean
role?: string
}
33 changes: 33 additions & 0 deletions frontend/src/app/pages/user-list/user-list.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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<UserListComponent>;
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();
});
});
6 changes: 5 additions & 1 deletion frontend/src/app/pages/user-list/user-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8eb613b

Please sign in to comment.