Skip to content

Commit

Permalink
Codegen test updates (#1877)
Browse files Browse the repository at this point in the history
* Add Swift codegen engine argument test
* Update test function names to match #1849
* Remove test file attribution header
  • Loading branch information
calvincestari committed Aug 23, 2021
1 parent 5d88128 commit af2c1ec
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions Tests/ApolloCodegenTests/ApolloCodegenTests.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// ApolloCodegenTests.swift
// ApolloCodegenTests
//
// Created by Ellen Shapiro on 10/7/19.
// Copyright © 2019 Apollo GraphQL. All rights reserved.
//

import XCTest
import ApolloCodegenTestSupport
@testable import ApolloCodegenLib
Expand All @@ -22,14 +14,13 @@ class ApolloCodegenTests: XCTestCase {
super.tearDown()
}

func testCreatingOptionsWithDefaultParameters() throws {
func testDesignatedInitializer_givenRequiredParameters_shouldBuildDefaultArguments() throws {
let sourceRoot = CodegenTestHelper.sourceRootURL()
let output = sourceRoot.appendingPathComponent("API.swift")
let schema = sourceRoot.appendingPathComponent("schema.json")

let options = ApolloCodegenOptions(outputFormat: .singleFile(atFileURL: output),
urlToSchemaFile: schema)


XCTAssertEqual(options.includes, "./**/*.graphql")
XCTAssertTrue(options.mergeInFieldsFromFragmentSpreads)
Expand Down Expand Up @@ -57,8 +48,25 @@ class ApolloCodegenTests: XCTestCase {
"'\(output.path)'",
])
}

func testConvenienceInitializer_givenAllParameters_shouldBuildCorrectArguments() throws {
let targetURL = URL(string: "file://could/be/anything/not/important")!
let options = ApolloCodegenOptions(targetRootURL: targetURL, codegenEngine: .swift, downloadTimeout: 42.0)

XCTAssertEqual(options.downloadTimeout, 42.0)
XCTAssertEqual(options.arguments, [
"codegen:generate",
"--target=json-modern",
"--addTypename",
"--includes=\'./**/*.graphql\'",
"--localSchemaFile=\'/be/anything/not/important/schema.json\'",
"--operationIdsPath=\'/be/anything/not/important/operationIDs.json\'",
"--mergeInFieldsFromFragmentSpreads",
"\'/be/anything/not/important/API.json\'"
])
}

func testCreatingOptionsWithAllParameters() throws {
func testDesignatedInitializer_givenAllParameters_shouldBuildCorrectArguments() throws {
let sourceRoot = CodegenTestHelper.sourceRootURL()
let output = sourceRoot.appendingPathComponent("API")
let schema = sourceRoot.appendingPathComponent("schema.json")
Expand Down Expand Up @@ -111,7 +119,7 @@ class ApolloCodegenTests: XCTestCase {
])
}

func testTryingToUseAFileURLToOutputMultipleFilesFails() {
func testMultipleFilesOutputFormat_givenAFileURL_shouldFail() {
let scriptFolderURL = CodegenTestHelper.cliFolderURL()
let starWarsFolderURL = CodegenTestHelper.starWarsFolderURL()
let starWarsSchemaFileURL = CodegenTestHelper.starWarsSchemaFileURL()
Expand All @@ -136,7 +144,7 @@ class ApolloCodegenTests: XCTestCase {
}
}

func testTryingToUseAFolderURLToOutputASingleFileFails() {
func testSingleFileOutputFormat_givenAFolderURL_shouldFail() {
let scriptFolderURL = CodegenTestHelper.cliFolderURL()
let starWarsFolderURL = CodegenTestHelper.starWarsFolderURL()
let starWarsSchemaFileURL = CodegenTestHelper.starWarsSchemaFileURL()
Expand All @@ -159,7 +167,7 @@ class ApolloCodegenTests: XCTestCase {
}
}

func testCodegenWithSingleFileOutputsSingleFile() throws {
func testSingleFileOutputFormat_givenAFileURL_shouldSucceed() throws {
let scriptFolderURL = CodegenTestHelper.cliFolderURL()
let starWarsFolderURL = CodegenTestHelper.starWarsFolderURL()
let starWarsSchemaFileURL = CodegenTestHelper.starWarsSchemaFileURL()
Expand All @@ -185,7 +193,7 @@ class ApolloCodegenTests: XCTestCase {
XCTAssertEqual(contents.count, 1)
}

func testCodegenWithMultipleFilesOutputsMultipleFiles() throws {
func testMultipleFilesOutputFormat_givenAFolderURL_shouldSucceed() throws {
let scriptFolderURL = CodegenTestHelper.cliFolderURL()
let starWarsFolderURL = CodegenTestHelper.starWarsFolderURL()
let starWarsSchemaFileURL = CodegenTestHelper.starWarsSchemaFileURL()
Expand Down

0 comments on commit af2c1ec

Please sign in to comment.