Merge pull request 'TrackScan Update bug 🐞bugfix/163-trackscan_updates' (#164) from bugfix/163-trackscan_updates into dev
continuous-integration/drone/push Build is failing Details

Reviewed-on: #164
This commit is contained in:
Nicolai Ort 2021-03-18 15:09:08 +00:00
commit 6249419fae
2 changed files with 15 additions and 16 deletions

View File

@ -1,9 +1,9 @@
import { IsBoolean, IsInt, IsOptional, IsPositive } from 'class-validator';
import { getConnection } from 'typeorm';
import { RunnerNotFoundError } from '../../../errors/RunnerErrors';
import { ScanStationNotFoundError } from '../../../errors/ScanStationErrors';
import { TrackNotFoundError } from '../../../errors/TrackErrors';
import { Runner } from '../../entities/Runner';
import { ScanStation } from '../../entities/ScanStation';
import { Track } from '../../entities/Track';
import { TrackScan } from '../../entities/TrackScan';
/**
@ -38,7 +38,7 @@ export abstract class UpdateTrackScan {
*/
@IsInt()
@IsPositive()
public station: number;
public track: number;
/**
* Update a TrackScan entity based on this.
@ -47,8 +47,7 @@ export abstract class UpdateTrackScan {
public async update(scan: TrackScan): Promise<TrackScan> {
scan.valid = this.valid;
scan.runner = await this.getRunner();
scan.station = await this.getStation();
scan.track = scan.station.track;
scan.track = await this.getTrack();
return scan;
}
@ -67,11 +66,11 @@ export abstract class UpdateTrackScan {
/**
* Gets a runner based on the runner id provided via this.runner.
*/
public async getStation(): Promise<ScanStation> {
const station = await getConnection().getRepository(ScanStation).findOne({ id: this.station }, { relations: ['track'] });
if (!station) {
throw new ScanStationNotFoundError();
public async getTrack(): Promise<Track> {
const track = await getConnection().getRepository(Track).findOne({ id: this.track });
if (!track) {
throw new TrackNotFoundError();
}
return station;
return track;
}
}

View File

@ -86,7 +86,7 @@ describe('adding + updating illegally', () => {
it('updating with wrong id should return 406', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id + 1,
"station": added_station.id,
"track": added_track.id,
"runner": added_runner.id
}, axios_config);
expect(res2.status).toEqual(406);
@ -95,7 +95,7 @@ describe('adding + updating illegally', () => {
it('updating with invalid station should return 404', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id,
"station": 9999999999999999,
"track": 9999999999999999,
"runner": added_runner.id
}, axios_config);
expect(res2.status).toEqual(404);
@ -104,7 +104,7 @@ describe('adding + updating illegally', () => {
it('updating with invalid runner should return 404', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id,
"station": added_station.id,
"track": added_station.id,
"runner": 9999999999999999999
}, axios_config);
expect(res2.status).toEqual(404);
@ -211,7 +211,7 @@ describe('adding + updating successfilly', () => {
it('updating with new runner should return 200', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id,
"station": added_station.id,
"track": added_track.id,
"runner": added_runner2.id
}, axios_config);
expect(res2.status).toEqual(200);
@ -220,7 +220,7 @@ describe('adding + updating successfilly', () => {
it('updating with new station should return 200', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id,
"station": added_station2.id,
"track": added_track2.id,
"runner": added_runner.id
}, axios_config);
expect(res2.status).toEqual(200);
@ -229,7 +229,7 @@ describe('adding + updating successfilly', () => {
it('updating with valid=false should return 200', async () => {
const res2 = await axios.put(base + '/api/scans/trackscans/' + added_scan.id, {
"id": added_scan.id,
"station": added_station2.id,
"track": added_track2.id,
"runner": added_runner.id,
"valid": false
}, axios_config);