Skip to content

Commit

Permalink
updated deployment file and added testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuldeep-knoldus committed Jul 2, 2024
1 parent fdf8334 commit c46b016
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 8 deletions.
83 changes: 76 additions & 7 deletions blogs-analyzer-ui/src/app/services/blog.service.spec.ts
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);
});
});
5 changes: 4 additions & 1 deletion blogs-analyzer/k8s/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ spec:
image: gcr.io/gen-lang-client-0999974873/blogs-analyzer:latest
env:
- name: GOOGLE_GEMINI_API_KEY
value: "AIzaSyBVXC1CEsJvqu3Lp9f_QuFoLYuzP3yJTGU"
valueFrom:
secretKeyRef:
name: google-api-key
key: api-key
ports:
- containerPort: 8081
resources:
Expand Down

0 comments on commit c46b016

Please sign in to comment.