From 95bf5665f6d681faa95ac3cbbafabec45b4e909c Mon Sep 17 00:00:00 2001 From: Marc VandenBerg Date: Wed, 28 Sep 2022 16:23:41 -0400 Subject: [PATCH] Update swift tests improved pluralization --- .../appsync-swift-visitor.test.ts.snap | 130 +++++++++++++++++- .../visitors/appsync-swift-visitor.test.ts | 6 +- 2 files changed, 130 insertions(+), 6 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-swift-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-swift-visitor.test.ts.snap index da8779268..19620cb6f 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-swift-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-swift-visitor.test.ts.snap @@ -967,19 +967,143 @@ exports[`AppSyncSwiftVisitor Use Improved Pluralization Should work with potenti "// swiftlint:disable all import Amplify import Foundation -" + +public struct Wish: Model { + public let id: String + public var date: Temporal.DateTime + public var idUser: String + public var ev: String + public var deprecated: Bool + public var owner: String? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + date: Temporal.DateTime, + idUser: String, + ev: String, + deprecated: Bool, + owner: String? = nil) { + self.init(id: id, + date: date, + idUser: idUser, + ev: ev, + deprecated: deprecated, + owner: owner, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + date: Temporal.DateTime, + idUser: String, + ev: String, + deprecated: Bool, + owner: String? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.date = date + self.idUser = idUser + self.ev = ev + self.deprecated = deprecated + self.owner = owner + self.createdAt = createdAt + self.updatedAt = updatedAt + } +}" `; exports[`AppSyncSwiftVisitor Use Improved Pluralization Should work with potentially pluralized collision 2`] = ` "// swiftlint:disable all import Amplify import Foundation -" + +extension Wish { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case date + case idUser + case ev + case deprecated + case owner + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let wish = Wish.keys + + model.listPluralName = \\"Wishes\\" + model.syncPluralName = \\"Wishes\\" + + model.attributes( + .index(fields: [\\"idUser\\"], name: \\"byUsers\\") + ) + + model.fields( + .id(), + .field(wish.date, is: .required, ofType: .dateTime), + .field(wish.idUser, is: .required, ofType: .string), + .field(wish.ev, is: .required, ofType: .string), + .field(wish.deprecated, is: .required, ofType: .bool), + .field(wish.owner, is: .optional, ofType: .string), + .field(wish.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(wish.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } +}" `; exports[`AppSyncSwiftVisitor Use Improved Pluralization Should work with potentially pluralized collision 3`] = ` "// swiftlint:disable all import Amplify import Foundation -" + +public struct Wishes: Model { + public let id: String + public var date: Temporal.DateTime + public var idUser: String + public var ev: String + public var deprecated: Bool + public var owner: String? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + date: Temporal.DateTime, + idUser: String, + ev: String, + deprecated: Bool, + owner: String? = nil) { + self.init(id: id, + date: date, + idUser: idUser, + ev: ev, + deprecated: deprecated, + owner: owner, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + date: Temporal.DateTime, + idUser: String, + ev: String, + deprecated: Bool, + owner: String? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.date = date + self.idUser = idUser + self.ev = ev + self.deprecated = deprecated + self.owner = owner + self.createdAt = createdAt + self.updatedAt = updatedAt + } +}" `; diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts index c34ca6198..5f0e7c75c 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts @@ -2321,7 +2321,7 @@ describe('AppSyncSwiftVisitor', () => { it('Should work with potentially pluralized collision', () => { const visitor = getVisitor( wishSchema, - 'ListContainer', + 'Wish', CodeGenGenerateEnum.code, { improvePluralization: true, @@ -2332,7 +2332,7 @@ describe('AppSyncSwiftVisitor', () => { const metadataVisitor = getVisitor( wishSchema, - 'ListContainer', + 'Wish', CodeGenGenerateEnum.metadata, { improvePluralization: true, @@ -2343,7 +2343,7 @@ describe('AppSyncSwiftVisitor', () => { const customTypeVisitor = getVisitor( wishSchema, - 'CustomType', + 'Wishes', CodeGenGenerateEnum.code, { improvePluralization: true,