Skip to content

Commit

Permalink
Add ImportStatementTemplate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calvincestari committed Mar 10, 2022
1 parent 2fe4b14 commit 4b44673
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@
E66F8899276C15580000BDA8 /* ObjectFileGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = E66F8898276C15580000BDA8 /* ObjectFileGenerator.swift */; };
E674DB41274C0A9B009BB90E /* Glob.swift in Sources */ = {isa = PBXBuildFile; fileRef = E674DB40274C0A9B009BB90E /* Glob.swift */; };
E674DB43274C0AD9009BB90E /* GlobTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E674DB42274C0AD9009BB90E /* GlobTests.swift */; };
E686B0D227D951630095D04E /* ImportStatementTemplateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E686B0D127D951630095D04E /* ImportStatementTemplateTests.swift */; };
E68D824527A1D8A60040A46F /* ObjectTemplateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E64F7EC227A1243A0059C021 /* ObjectTemplateTests.swift */; };
E68D824727A228A80040A46F /* SchemaModuleFileGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = E68D824627A228A80040A46F /* SchemaModuleFileGenerator.swift */; };
E69BEDA52798B86D00000D10 /* InputObjectTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E69BEDA42798B86D00000D10 /* InputObjectTemplate.swift */; };
Expand Down Expand Up @@ -1105,6 +1106,7 @@
E66F8898276C15580000BDA8 /* ObjectFileGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectFileGenerator.swift; sourceTree = "<group>"; };
E674DB40274C0A9B009BB90E /* Glob.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Glob.swift; sourceTree = "<group>"; };
E674DB42274C0AD9009BB90E /* GlobTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobTests.swift; sourceTree = "<group>"; };
E686B0D127D951630095D04E /* ImportStatementTemplateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportStatementTemplateTests.swift; sourceTree = "<group>"; };
E68D824627A228A80040A46F /* SchemaModuleFileGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SchemaModuleFileGenerator.swift; sourceTree = "<group>"; };
E69BEDA42798B86D00000D10 /* InputObjectTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputObjectTemplate.swift; sourceTree = "<group>"; };
E69BEDA62798B89600000D10 /* InputObjectTemplateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputObjectTemplateTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2089,6 +2091,7 @@
DE5FD608276956C70033EE23 /* SchemaTemplateTests.swift */,
E6B42D0C27A4749100A3BD58 /* SwiftPackageManagerModuleTemplateTests.swift */,
E64F7EB927A085D90059C021 /* UnionTemplateTests.swift */,
E686B0D127D951630095D04E /* ImportStatementTemplateTests.swift */,
);
path = Templates;
sourceTree = "<group>";
Expand Down Expand Up @@ -3310,6 +3313,7 @@
E6B42D0D27A4749100A3BD58 /* SwiftPackageManagerModuleTemplateTests.swift in Sources */,
9F62DFBF2590560000E6E808 /* Helpers.swift in Sources */,
DE296539279B3B8200BF9B49 /* SelectionSetTemplateTests.swift in Sources */,
E686B0D227D951630095D04E /* ImportStatementTemplateTests.swift in Sources */,
E66F8897276C136B0000BDA8 /* ObjectFileGeneratorTests.swift in Sources */,
DE79642B276999E700978A03 /* IRNamedFragmentBuilderTests.swift in Sources */,
E69BEDA72798B89600000D10 /* InputObjectTemplateTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import XCTest
@testable import ApolloCodegenLib
import Nimble
import ApolloCodegenTestSupport

class ImportStatementTemplateTests: XCTestCase {

var config: ApolloCodegenConfiguration.FileOutput!

override func tearDown() {
config = nil

super.tearDown()
}

// MARK: Helpers

func buildConfig(
moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType,
operations: ApolloCodegenConfiguration.OperationsFileOutput
) {
config = .mock(
moduleType: moduleType,
schemaName: "ImportStatementTestsSchema",
operations: operations
)
}

// MARK: Tests for operations generated into the schema module (schema module import not expected)

func test__operationRender__givenOperationsOutput_inSchemaModule_whenModuleType_none_generatesImportNotIncludingSchemaName() throws {
// given
buildConfig(
moduleType: .none,
operations: .inSchemaModule
)

let expected =
"""
import ApolloAPI
"""

// when
let actual = ImportStatementTemplate.Operation.render(config).description

// then
expect(actual).to(equalLineByLine(expected))
}

func test__operationRender__givenOperationsOutput_inSchemaModule_whenModuleType_swiftPackageManager_generatesImportNotIncludingSchemaName() throws {
// given
buildConfig(
moduleType: .swiftPackageManager,
operations: .inSchemaModule
)

let expected =
"""
import ApolloAPI
"""

// when
let actual = ImportStatementTemplate.Operation.render(config).description

// then
expect(actual).to(equalLineByLine(expected))
}

func test__operationRender__givenOperationsOutput_inSchemaModule_whenModuleType_other_generatesImportNotIncludingSchemaName() throws {
// given
buildConfig(
moduleType: .other,
operations: .inSchemaModule
)

let expected =
"""
import ApolloAPI
"""

// when
let actual = ImportStatementTemplate.Operation.render(config).description

// then
expect(actual).to(equalLineByLine(expected))
}

// MARK: Tests for operations generated outside the schema module

func test__operationRender__givenOperationsOutput_relative_whenModuleType_none_generatesImportNotIncludingSchemaName() throws {
// given
buildConfig(
moduleType: .none,
operations: .relative(subpath: nil)
)

let expected =
"""
import ApolloAPI
"""

// when
let actual = ImportStatementTemplate.Operation.render(config).description

// then
expect(actual).to(equalLineByLine(expected))
}

func test__operationRender__givenOperationsOutput_relative_whenModuleType_swiftPackageManager_generatesImportIncludingSchemaName() throws {
// given
buildConfig(
moduleType: .swiftPackageManager,
operations: .relative(subpath: nil)
)

let expected =
"""
import ApolloAPI
import ImportStatementTestsSchema
"""

// when
let actual = ImportStatementTemplate.Operation.render(config).description

// then
expect(actual).to(equalLineByLine(expected))
}

func test__operationRender__givenOperationsOutput_relative_whenModuleType_other_generatesImportIncludingSchemaName() throws {
// given
buildConfig(
moduleType: .other,
operations: .relative(subpath: nil)
)

let expected =
"""
import ApolloAPI
import ImportStatementTestsSchema
"""

// when
let actual = ImportStatementTemplate.Operation.render(config).description

// then
expect(actual).to(equalLineByLine(expected))
}

func test__operationRender__givenOperationsOutput_absolute_whenModuleType_none_generatesImportNotIncludingSchemaName() throws {
// given
buildConfig(
moduleType: .none,
operations: .absolute(path: "path")
)

let expected =
"""
import ApolloAPI
"""

// when
let actual = ImportStatementTemplate.Operation.render(config).description

// then
expect(actual).to(equalLineByLine(expected))
}

func test__operationRender__givenOperationsOutput_absolute_whenModuleType_swiftPackageManager_generatesImportIncludingSchemaName() throws {
// given
buildConfig(
moduleType: .swiftPackageManager,
operations: .absolute(path: "path")
)

let expected =
"""
import ApolloAPI
import ImportStatementTestsSchema
"""

// when
let actual = ImportStatementTemplate.Operation.render(config).description

// then
expect(actual).to(equalLineByLine(expected))
}

func test__operationRender__givenOperationsOutput_absolute_whenModuleType_other_generatesImportIncludingSchemaName() throws {
// given
buildConfig(
moduleType: .other,
operations: .absolute(path: "path")
)

let expected =
"""
import ApolloAPI
import ImportStatementTestsSchema
"""

// when
let actual = ImportStatementTemplate.Operation.render(config).description

// then
expect(actual).to(equalLineByLine(expected))
}
}

0 comments on commit 4b44673

Please sign in to comment.