Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: TT-466 First commit for clockout frontend
  • Loading branch information
gcobena-dev committed Dec 23, 2021
commit 5a1ed1d2fc5cd82dd6cdb912feaeb84274c479b0
18 changes: 9 additions & 9 deletions src/app/modules/time-clock/services/entry.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,12 @@ describe('EntryService', () => {
});

it('loads an activeEntry with /running', () => {
service.urlInProduction = true;
service.loadActiveEntry().subscribe();

const loadEntryRequest = httpMock.expectOne(`${service.baseUrl}/running`);
expect(loadEntryRequest.request.method).toBe('GET');
});

it('loads an activeEntry with /active/{userId}', () => {
service.urlInProduction = false;
service.loadActiveEntry().subscribe();

const loadEntryRequest = httpMock.expectOne(`${service.baseUrl}/active/2`);
expect(loadEntryRequest.request.method).toBe('GET');
});

it('loads summary with get /summary?time_offset=<time-offset>', () => {
service.summary().subscribe();
const timeOffset = new Date().getTimezoneOffset();
Expand Down Expand Up @@ -93,12 +84,21 @@ describe('EntryService', () => {
});

it('stops an entry using POST', () => {
service.urlInProduction = true;
service.stopEntryRunning('id').subscribe();

const updateEntryRequest = httpMock.expectOne(`${service.baseUrl}/id/stop`);
expect(updateEntryRequest.request.method).toBe('POST');
});

it('stops an entry using PUT', () => {
service.urlInProduction = false;
service.stopEntryRunning('id').subscribe();

const updateEntryRequest = httpMock.expectOne(`${service.baseUrl}/stop`);
expect(updateEntryRequest.request.method).toBe('PUT');
});

it('when getting time entries for report, time range should be sent', () => {
const yesterday = moment(new Date()).subtract(1, 'day');
const today = moment(new Date());
Expand Down
20 changes: 10 additions & 10 deletions src/app/modules/time-clock/services/entry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ export class EntryService {
urlInProduction = environment.production;

loadActiveEntry(): Observable<any> {
let path = '';

if (this.urlInProduction){
path = `${this.baseUrl}/running`;
}else{
path = `${this.baseUrl}/active/2`;
}
return this.http.get(path);
return this.http.get(`${this.baseUrl}/running`);
}

loadEntries(date): Observable<any> {
Expand All @@ -52,8 +45,15 @@ export class EntryService {
}

stopEntryRunning(idEntry: string): Observable<any> {
const url = `${this.baseUrl}/${idEntry}/stop`;
return this.http.post(url, null);
let path = '';

if (this.urlInProduction){
path = `${this.baseUrl}/${idEntry}/stop`;
return this.http.post(path, null);
}else{
path = `${this.baseUrl}/stop`;
return this.http.put(path, null);
}
}

restartEntry(idEntry: string): Observable<Entry> {
Expand Down