Add API for django messages
This commit is contained in:
35
src-ui/src/app/services/messages.service.spec.ts
Normal file
35
src-ui/src/app/services/messages.service.spec.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { MessagesService } from './messages.service'
|
||||
|
||||
import {
|
||||
HttpClientTestingModule,
|
||||
HttpTestingController,
|
||||
} from '@angular/common/http/testing'
|
||||
import { environment } from 'src/environments/environment'
|
||||
|
||||
describe('MessagesService', () => {
|
||||
let httpTestingController: HttpTestingController
|
||||
let service: MessagesService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [MessagesService],
|
||||
imports: [HttpClientTestingModule],
|
||||
})
|
||||
httpTestingController = TestBed.inject(HttpTestingController)
|
||||
service = TestBed.inject(MessagesService)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
httpTestingController.verify()
|
||||
})
|
||||
|
||||
it('calls get profile endpoint', () => {
|
||||
service.get().subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}messages/`
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
})
|
||||
})
|
||||
25
src-ui/src/app/services/messages.service.ts
Normal file
25
src-ui/src/app/services/messages.service.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Observable } from 'rxjs'
|
||||
import { environment } from 'src/environments/environment'
|
||||
|
||||
export interface DjangoMessage {
|
||||
level: string
|
||||
message: string
|
||||
tags: string
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class MessagesService {
|
||||
private endpoint = 'messages'
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
get(): Observable<DjangoMessage[]> {
|
||||
return this.http.get<DjangoMessage[]>(
|
||||
`${environment.apiBaseUrl}${this.endpoint}/`
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user