Skip to content

test(data): Gen2 data customize data model doc example testing #3699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

lawmicha
Copy link
Contributor

@lawmicha lawmicha commented May 15, 2024

Issue #

Description

This PR uses the schemas from the Gen2 docs and runs integration tests against them to verify code snippet compiles and functions as expected at runtime. The code snippets are then moved over to the docs PR #3699

Found an issue with one-to-one, tracking in #3735

General Checklist

  • Added new tests to cover change, if needed
  • Build succeeds with all target using Swift Package Manager
  • All unit tests pass
  • All integration tests pass
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Documentation update for the change if required
  • PR title conforms to conventional commit style
  • New or updated tests include Given When Then inline code documentation and are named accordingly testThing_condition_expectation()
  • If breaking change, documentation/changelog update with migration instructions

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lawmicha
Copy link
Contributor Author

on Swift codegen, this doesn't compile

// Gen2_4 - Model a "one-to-one" relationship
    // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#model-a-one-to-one-relationship
    Cart4: a.model({
        items: a.string().required().array(),
        // 1. Create reference field
        customerId: a.id(),
        // 2. Create relationship field with the reference field
        customer: a.belongsTo('Customer4', 'customerId'),
    }),
    Customer4: a.model({
        name: a.string(),
        // 3. Create relationship field with the reference field
        //    from the Cart model
        activeCart: a.hasOne('Cart4', 'customerId')
    }),

Customer4 schema has

.hasOne(customer4.activeCart, is: .optional, ofType: Cart4.self, associatedFields: [Cart4.keys.customer]),

hasOne associatedFields doesn't exist. I think we might be able to easily add it. do we need to add targetName as well? Those methods are defined over in https://github.com/aws-amplify/amplify-swift/blob/main/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema%2BDefinition.swift#L232-L306

Copy link

codecov bot commented May 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.06%. Comparing base (d888124) to head (eb4b388).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3699      +/-   ##
==========================================
+ Coverage   68.37%   70.06%   +1.68%     
==========================================
  Files        1096      637     -459     
  Lines       38089    24773   -13316     
==========================================
- Hits        26044    17356    -8688     
+ Misses      12045     7417    -4628     
Flag Coverage Δ
API_plugin_unit_test 68.96% <ø> (ø)
AWSPluginsCore 65.67% <ø> (ø)
Amplify ?
Analytics_plugin_unit_test 84.52% <ø> (ø)
Auth_plugin_unit_test 79.27% <ø> (-0.20%) ⬇️
CoreMLPredictions_plugin_unit_test 61.15% <ø> (ø)
DataStore_plugin_unit_test ?
Geo_plugin_unit_test 73.50% <ø> (ø)
Logging_plugin_unit_test 62.87% <ø> (ø)
Predictions_plugin_unit_test 37.31% <ø> (ø)
PushNotifications_plugin_unit_test 86.21% <ø> (ø)
Storage_plugin_unit_test 76.75% <ø> (ø)
unit_tests 70.06% <ø> (+1.68%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@thisisabhash thisisabhash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, minor comments

let createdPost = try await Amplify.API.mutate(request: .create(post)).get()
print("\(createdPost)")

XCTAssertEqual(createdPost.location?.lat, 48.837006)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a note: since we are comparing floating point, hopefully XCTAssertEqual uses
https://developer.apple.com/documentation/swift/double/isequal(to:)
in case this test becomes flaky

}),

// Gen2_41 -Model multiple relationships between two models
// http://localhost:3000/swift/build-a-backend/data/data-modeling/relationships/#model-multiple-relationships-between-two-models
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: change the local url to docs url

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, i'll merge this PR in first and update this line in the other one #3705 to avoid rebasing since that one and is merging into this branch and also has some minor changes to do

@lawmicha lawmicha merged commit d2454d8 into main Jun 3, 2024
85 of 148 checks passed
@lawmicha lawmicha deleted the docs.data branch June 3, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants