-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated deployment file and added testcase
- Loading branch information
1 parent
fdf8334
commit c46b016
Showing
2 changed files
with
80 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,93 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
import { BlogService } from './blog.service'; | ||
import { QualityCheckComponent } from "../quality-check/quality-check.component"; | ||
import { HeaderComponent } from "../dashboard/components/header/header.component"; | ||
import { RouterTestingModule } from "@angular/router/testing"; | ||
import { HttpClientModule } from "@angular/common/http"; | ||
import { environment } from '../../environments/environment'; | ||
|
||
describe('BlogService', () => { | ||
let service: BlogService; | ||
let httpMock: HttpTestingController; | ||
const baseUrl = environment.apiUrl; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [BlogService], | ||
declarations: [QualityCheckComponent, HeaderComponent], | ||
imports: [RouterTestingModule, HttpClientModule] | ||
imports: [HttpClientTestingModule] | ||
}); | ||
service = TestBed.inject(BlogService); | ||
httpMock = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
afterEach(() => { | ||
httpMock.verify(); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should search posts by title', () => { | ||
const mockResponse = 'mock response'; | ||
const title = 'test'; | ||
service.searchPostsByTitle(title).subscribe(response => { | ||
expect(response).toBe(mockResponse); | ||
}); | ||
|
||
const req = httpMock.expectOne(`${baseUrl}/wordpress/posts-by-title?title=${encodeURIComponent(title)}`); | ||
expect(req.request.method).toBe('GET'); | ||
req.flush(mockResponse); | ||
}); | ||
|
||
it('should get all posts', () => { | ||
const mockResponse = { | ||
posts: [{id: 1, title: 'Test Post'}], | ||
totalPages: 1 | ||
}; | ||
const page = 1; | ||
const pageSize = 10; | ||
service.getAllPosts(page, pageSize).subscribe(response => { | ||
expect(response.posts).toEqual(mockResponse.posts); | ||
expect(response.totalPages).toBe(mockResponse.totalPages); | ||
}); | ||
|
||
const req = httpMock.expectOne(`${baseUrl}/wordpress?page=${page}&size=${pageSize}`); | ||
expect(req.request.method).toBe('GET'); | ||
req.flush(mockResponse); | ||
}); | ||
|
||
it('should get post by id', () => { | ||
const mockResponse = 'mock post'; | ||
const id = 1; | ||
service.getPostById(id).subscribe(response => { | ||
expect(response).toBe(mockResponse); | ||
}); | ||
|
||
const req = httpMock.expectOne(`${baseUrl}/wordpress/posts/${id}`); | ||
expect(req.request.method).toBe('GET'); | ||
req.flush(mockResponse); | ||
}); | ||
|
||
it('should get post by author id', () => { | ||
const mockResponse = 'mock response'; | ||
const id = 1; | ||
service.getPostByAuthorId(id).subscribe(response => { | ||
expect(response).toBe(mockResponse); | ||
}); | ||
|
||
const req = httpMock.expectOne(`${baseUrl}/wordpress/posts-by-author?authorId=${id}`); | ||
expect(req.request.method).toBe('GET'); | ||
req.flush(mockResponse); | ||
}); | ||
|
||
it('should get blog quality', () => { | ||
const mockResponse = 'mock response'; | ||
const prompt = 'test prompt'; | ||
service.getBlogQuality(prompt).subscribe(response => { | ||
expect(response).toBe(mockResponse); | ||
}); | ||
|
||
const req = httpMock.expectOne(`${baseUrl}/gemini/v1/review`); | ||
expect(req.request.method).toBe('POST'); | ||
expect(req.request.body).toBe(prompt); | ||
req.flush(mockResponse); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters