Skip to content
Snippets Groups Projects
Commit 6518bc0b authored by Jonny Ngo Luong's avatar Jonny Ngo Luong
Browse files

test: tests fixed (#33)

parent c1455c14
Branches Badges
No related tags found
1 merge request!34Resolve "Annonser filtrert nær brukeren etter sted i hjemmesiden"
Pipeline #126197 passed
......@@ -32,7 +32,8 @@ describe('PostListComponent', () => {
owner: "user",
imageUrl: null,
price: 49,
categoryid: 1
categoryid: 1,
status: 0,
}),
new Post({
id: 2,
......@@ -42,7 +43,8 @@ describe('PostListComponent', () => {
owner: "user",
imageUrl: null,
price: 159,
categoryid: 2
categoryid: 2,
status: 0,
})
]);
})
......@@ -58,7 +60,8 @@ describe('PostListComponent', () => {
owner: "user",
imageUrl: null,
price: 49,
categoryid: 1
categoryid: 1,
status: 0,
})
]);
})
......
......@@ -265,7 +265,7 @@ describe('PostService', () => {
describe('getPostsByCategory', () => {
it('should get posts by category', () => {
// Gets posts by category and checks values
service.getPostsByCategory(2, 0, 0, 100).then(posts => {
service.getPostsByCategory(2, undefined, 0, 0, 100).then(posts => {
for (let i = 0; i < posts.length; i++) {
expect(posts[i].getId).toBe(i + 1);
expect(posts[i].getTitle).toBe("Test" + (i + 1));
......@@ -276,7 +276,7 @@ describe('PostService', () => {
});
// Mocks and checks HTTP request
const req = httpMock.expectOne("api/post/?categoryid=2&sort=0&min_price=0&max_price=100");
const req = httpMock.expectOne("api/post/?categoryid=2&location=undefined&sort=0&min_price=0&max_price=100");
expect(req.request.method).toBe("GET");
req.flush({
data: [{
......@@ -303,12 +303,12 @@ describe('PostService', () => {
it('should reject on invalid post', () => {
// Gets invalid post, should go to catch
service.getPostsByCategory(52, 0, 0, 100).then(posts => {
service.getPostsByCategory(52, undefined, 0, 0, 100).then(posts => {
fail();
}).catch(error => {});
// Mocks and checks HTTP request
const req = httpMock.expectOne("api/post/?categoryid=52&sort=0&min_price=0&max_price=100");
const req = httpMock.expectOne("api/post/?categoryid=52&location=undefined&sort=0&min_price=0&max_price=100");
expect(req.request.method).toBe("GET");
req.flush({
data: [{
......@@ -322,12 +322,12 @@ describe('PostService', () => {
it('should reject on http error', () => {
// Gets HTTP error instead of post, should catch
service.getPostsByCategory(35, 0, 0, 100).then(post => {
service.getPostsByCategory(35, undefined, 0, 0, 100).then(post => {
fail();
}).catch(error => {});
// Mocks and checks HTTP request
const req = httpMock.expectOne("api/post/?categoryid=35&sort=0&min_price=0&max_price=100");
const req = httpMock.expectOne("api/post/?categoryid=35&location=undefined&sort=0&min_price=0&max_price=100");
expect(req.request.method).toBe("GET");
req.error(new ErrorEvent("400"));
});
......
......@@ -4,6 +4,7 @@ import { ActivatedRoute } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { Review } from 'src/app/models/review.model';
import { User } from 'src/app/models/user.model';
import { UserLoginFormComponent } from '../user-login-form/user-login-form.component';
import { UserService } from '../user.service';
import { UserGuestProfileComponent } from './user-guest-profile.component';
......@@ -42,7 +43,13 @@ describe('UserGuestProfileComponent', () => {
await TestBed.configureTestingModule({
declarations: [ UserGuestProfileComponent ],
imports: [ HttpClientTestingModule, RouterTestingModule ],
imports: [
HttpClientTestingModule,
RouterTestingModule.withRoutes([
{ path: 'user', component: UserGuestProfileComponent},
{ path: 'login', component: UserLoginFormComponent},
])
],
providers: [
{ provide: ActivatedRoute, useValue: { snapshot: {params: {id: 1}}}},
{ provide: UserService, useValue: mockUserService }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment