-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fe4b14
commit 4b44673
Showing
2 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
Tests/ApolloCodegenTests/CodeGeneration/Templates/ImportStatementTemplateTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |