Skip to content

Commit

Permalink
test: Add JSON conversion sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Semenov committed Sep 18, 2023
1 parent 7942a10 commit 3111517
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Radar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
2F0F463C2AB8C54700DCFF05 /* RemoteDataConversionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F0F463B2AB8C54700DCFF05 /* RemoteDataConversionSpec.swift */; };
2F3A24AB2968FDCE00DB071B /* FetchTokenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F3A24AA2968FDCE00DB071B /* FetchTokenView.swift */; };
2F3A24AD2969002200DB071B /* PipelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F3A24AC2969002200DB071B /* PipelineView.swift */; };
2F3A24AF296901BB00DB071B /* DashboardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F3A24AE296901BB00DB071B /* DashboardView.swift */; };
Expand Down Expand Up @@ -57,6 +58,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
2F0F463B2AB8C54700DCFF05 /* RemoteDataConversionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteDataConversionSpec.swift; sourceTree = "<group>"; };
2F3A24AA2968FDCE00DB071B /* FetchTokenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchTokenView.swift; sourceTree = "<group>"; };
2F3A24AC2969002200DB071B /* PipelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PipelineView.swift; sourceTree = "<group>"; };
2F3A24AE296901BB00DB071B /* DashboardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -188,6 +190,7 @@
E1136DF4E174B54A906A2672 /* PipelineSpec.swift */,
E1136E630A4C0ED4C7164841 /* TeamSpec.swift */,
E1136708BD2783BF94465981 /* Fixtures.swift */,
2F0F463B2AB8C54700DCFF05 /* RemoteDataConversionSpec.swift */,
);
path = RadarTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -374,6 +377,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2F0F463C2AB8C54700DCFF05 /* RemoteDataConversionSpec.swift in Sources */,
2F872B1F2971DAB500B4144D /* AppDataConverterSpec.swift in Sources */,
2F872B212971EF1900B4144D /* JobSpec.swift in Sources */,
E1136B212ED16E7A7BA5F134 /* PipelineSpec.swift in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion Radar/ConcourseJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ struct JobInput: Codable {

struct ConcourseJob: Codable, Identifiable {
enum CodingKeys: String, CodingKey {
case id, name, teamName, inputs
case id, name, inputs
case teamName = "team_name"
case pipelineId = "pipeline_id"
case pipelineName = "pipeline_name"
case finishedBuild = "finished_build"
Expand Down
26 changes: 26 additions & 0 deletions RadarTests/RemoteDataConversionSpec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: Apache-2.0

import Quick
import Nimble
import Foundation
@testable import Radar

class RemoteDataConversionSpec: QuickSpec {
let samplePipelines = "[{\"id\": 33937,\"name\": \"slack-delegate-bot\",\"paused\": false,\"public\": false,\"archived\": false,\"team_name\": \"dash-core\",\"last_updated\": 1694500551}]"
let sampleJobs = "[{\"id\":87813,\"name\":\"build-and-push-image\",\"team_name\":\"davros\",\"pipeline_id\":3845,\"pipeline_name\":\"davros\",\"groups\":[\"secondary\",\"all\"],\"finished_build\":{\"id\":1420927292,\"name\":\"27.1\",\"status\":\"succeeded\",\"start_time\":1671440226,\"end_time\":1671440994,\"team_name\":\"davros\",\"pipeline_id\":3845,\"pipeline_name\":\"davros\",\"job_name\":\"build-and-push-image\"},\"transition_build\":{\"id\":1420927292,\"name\":\"27.1\",\"status\":\"succeeded\",\"start_time\":1671440226,\"end_time\":1671440994,\"team_name\":\"davros\",\"pipeline_id\":3845,\"pipeline_name\":\"davros\",\"job_name\":\"build-and-push-image\"},\"inputs\":[{\"name\":\"master-image-src\",\"resource\":\"master-image-src\"}],\"outputs\":[{\"name\":\"master-image\",\"resource\":\"master-image\"}]}]"
let sampleTeams = "[{\"id\":2385,\"name\":\"cybergenics\",\"auth\":{\"member\":{\"groups\":[],\"users\":[\"this\",\"is\",\"the\",\"house\",\"that\",\"jack\",\"built\",\"malt\",\"lay\",\"rat\"]},\"owner\":{\"groups\":[],\"users\":[\"local:worker\",\"local:concourse\"]},\"pipeline-operator\":{\"groups\":[],\"users\":[\"pipeline-user\",\"operator-user\"]},\"viewer\":{\"groups\":[],\"users\":[\"viewer-user\"]}}}]"

override func spec() {
it("converts pipelines from JSON") {
expect { try JSONDecoder().decode([ConcoursePipeline].self, from: self.samplePipelines.data(using: .utf8)!) }.notTo(throwError())
}

it("converts jobs from JSON") {
expect { try JSONDecoder().decode([ConcourseJob].self, from: self.sampleJobs.data(using: .utf8)!) }.notTo(throwError())
}

it("converts teams from JSON") {
expect { try JSONDecoder().decode([ConcourseTeam].self, from: self.sampleTeams.data(using: .utf8)!) }.notTo(throwError())
}
}
}

0 comments on commit 3111517

Please sign in to comment.