Skip to content

Commit

Permalink
chore: Merging changes to release (#10481)
Browse files Browse the repository at this point in the history
<!--
Please make sure to read the Pull Request Guidelines:

https://github.com/aws-amplify/amplify-js/blob/main/CONTRIBUTING.md#pull-requests
-->

#### Description of changes
<!--
Thank you for your Pull Request! Please provide a description above and
review
the requirements below.
-->


#### Issue #, if available
<!-- Also, please reference any associated PRs for documentation
updates. -->



#### Description of how you validated changes



#### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to
[x]. -->

- [ ] PR description included
- [ ] `yarn test` passes
- [ ] Tests are [changed or
added](https://github.com/aws-amplify/amplify-js/blob/main/CONTRIBUTING.md#steps-towards-contributions)
- [ ] Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
  • Loading branch information
stocaaro authored Oct 14, 2022
2 parents 1728ea7 + 42ae8de commit bd5a9ad
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 173 deletions.
73 changes: 65 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1173,21 +1173,55 @@ jobs:
spec: next-owner-based-default
browser: << parameters.browser >>

integ_react_datastore_custom_pk:
integ_react_datastore_custom_pk_unconnected_models:
parameters:
browser:
type: string
executor: js-test-executor
<<: *test_env_vars
working_directory: ~/amplify-js-samples-staging/samples/react/datastore/v2/custom-pk
working_directory: ~/amplify-js-samples-staging/samples/react/datastore/v2/custom-pk-unconnected-models
steps:
- prepare_test_env
- integ_test_js:
test_name: 'DataStore - Custom Primary Key'
test_name: 'DataStore - Custom Primary Key (Connected Models)'
framework: react
category: datastore
sample_name: v2/custom-pk
spec: custom-pk
sample_name: v2/custom-pk-unconnected-models
spec: custom-pk-unconnected-models
browser: << parameters.browser >>

integ_react_datastore_custom_pk_has_one:
parameters:
browser:
type: string
executor: js-test-executor
<<: *test_env_vars
working_directory: ~/amplify-js-samples-staging/samples/react/datastore/v2/custom-pk-has-one
steps:
- prepare_test_env
- integ_test_js:
test_name: 'DataStore - Custom Primary Key (Has One)'
framework: react
category: datastore
sample_name: v2/custom-pk-has-one
spec: custom-pk-has-one
browser: << parameters.browser >>

integ_react_datastore_custom_pk_has_many_many_to_many:
parameters:
browser:
type: string
executor: js-test-executor
<<: *test_env_vars
working_directory: ~/amplify-js-samples-staging/samples/react/datastore/v2/custom-pk-has-many-many-to-many
steps:
- prepare_test_env
- integ_test_js:
test_name: 'DataStore - Custom Primary Key (Has Many / Many to Many)'
framework: react
category: datastore
sample_name: v2/custom-pk-has-many-many-to-many
spec: custom-pk-has-many-many-to-many
browser: << parameters.browser >>

deploy:
Expand Down Expand Up @@ -1236,7 +1270,6 @@ releasable_branches: &releasable_branches
- ui-components/main
- 1.0-stable
- geo/main
- ds-custom-pk

test_browsers: &test_browsers
browser: [chrome, firefox]
Expand Down Expand Up @@ -1644,7 +1677,29 @@ workflows:
matrix:
parameters:
<<: *test_browsers
- integ_react_datastore_custom_pk:
- integ_react_datastore_custom_pk_unconnected_models:
requires:
- integ_setup
- build
filters:
<<: *releasable_branches
matrix:
parameters:
# TODO: restore this after CPK flakiness on Chrome is resolved
# <<: *test_browsers
browser: [firefox]
- integ_react_datastore_custom_pk_has_one:
requires:
- integ_setup
- build
filters:
<<: *releasable_branches
matrix:
parameters:
# TODO: restore this after CPK flakiness on Chrome is resolved
# <<: *test_browsers
browser: [firefox]
- integ_react_datastore_custom_pk_has_many_many_to_many:
requires:
- integ_setup
- build
Expand Down Expand Up @@ -1703,7 +1758,9 @@ workflows:
- integ_react_graphql_api
- integ_react_geo
- integ_next_datastore_owner_auth
- integ_react_datastore_custom_pk
- integ_react_datastore_custom_pk_unconnected_models
- integ_react_datastore_custom_pk_has_one
- integ_react_datastore_custom_pk_has_many_many_to_many
- post_release:
filters:
branches:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
// Optionally specify a single test file to run/debug:
"storage.test.ts",
"sync.test.ts",
"--runInBand",
"--testTimeout",
"600000", // 10 min timeout so jest doesn't error while we're stepping through code
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
"publish:1.0-stable": "lerna publish --conventional-commits --yes --dist-tag=stable-1.0 --message 'chore(release): Publish [ci skip]' --no-verify-access",
"publish:ui-components/main": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=ui-preview --preid=ui-preview --exact --no-verify-access",
"publish:verdaccio": "lerna publish --no-push --canary minor --dist-tag=unstable --preid=unstable --exact --force-publish --yes --no-verify-access",
"publish:geo/main": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=geo --preid=geo --exact --no-verify-access",
"publish:ds-custom-pk": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=custom-pk --preid=custom-pk --exact --no-verify-access",
"temp-ds-safe-push": "yarn build --scope @aws-amplify/datastore && yarn test --scope @aws-amplify/datastore && git push origin"
"publish:geo/main": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=geo --preid=geo --exact --no-verify-access"
},
"husky": {
"hooks": {
Expand Down
27 changes: 1 addition & 26 deletions packages/datastore/__tests__/__snapshots__/sync.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Object {
}
`;

exports[`Sync jitteredRetry should return partial data and send Hub event when datastorePartialData is set 1`] = `
exports[`Sync jitteredRetry should return partial data and send Hub event 1`] = `
Object {
"data": Object {
"syncPosts": Object {
Expand All @@ -62,31 +62,6 @@ Object {
}
`;

exports[`Sync jitteredRetry should throw error and NOT return data or send Hub event when datastorePartialData is not set 1`] = `
Object {
"data": Object {
"syncPosts": Object {
"items": Array [
Object {
"id": "1",
"title": "Item 1",
},
null,
Object {
"id": "3",
"title": "Item 3",
},
],
},
},
"errors": Array [
Object {
"message": "Item 2 error",
},
],
}
`;

exports[`Sync jitteredRetry should throw error if no data is returned 1`] = `
Object {
"data": null,
Expand Down
60 changes: 2 additions & 58 deletions packages/datastore/__tests__/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe('Sync', () => {
});

it('should return all data', async () => {
window.sessionStorage.setItem('datastorePartialData', 'true');
const resolveResponse = {
data: {
syncPosts: {
Expand Down Expand Up @@ -87,7 +86,6 @@ describe('Sync', () => {
});

it('custom pk: should return all data', async () => {
window.sessionStorage.setItem('datastorePartialData', 'true');
const resolveResponse = {
data: {
syncPosts: {
Expand Down Expand Up @@ -119,8 +117,7 @@ describe('Sync', () => {
expect(data).toMatchSnapshot();
});

it('should return partial data and send Hub event when datastorePartialData is set', async () => {
window.sessionStorage.setItem('datastorePartialData', 'true');
it('should return partial data and send Hub event', async () => {
const rejectResponse = {
data: {
syncPosts: {
Expand Down Expand Up @@ -168,7 +165,7 @@ describe('Sync', () => {
expect(data).toMatchSnapshot();

expect(hubDispatchMock).toHaveBeenCalledWith('datastore', {
event: 'syncQueriesPartialSyncError',
event: 'nonApplicableDataReceived',
data: {
errors: [
{
Expand All @@ -180,58 +177,7 @@ describe('Sync', () => {
});
});

it('should throw error and NOT return data or send Hub event when datastorePartialData is not set', async () => {
const rejectResponse = {
data: {
syncPosts: {
items: [
{
id: '1',
title: 'Item 1',
},
null,
{
id: '3',
title: 'Item 3',
},
],
},
},
errors: [
{
message: 'Item 2 error',
},
],
};

const hubDispatchMock = jest.fn();
const coreMocks = {
Hub: {
dispatch: hubDispatchMock,
listen: jest.fn(),
},
};

const SyncProcessor = jitteredRetrySyncProcessorSetup({
rejectResponse,
coreMocks,
});

try {
await SyncProcessor.jitteredRetry({
query: defaultQuery,
variables: defaultVariables,
opName: defaultOpName,
modelDefinition: defaultModelDefinition,
authMode: defaultAuthMode,
});
} catch (e) {
expect(e).toMatchSnapshot();
}
});

it('should throw error if no data is returned', async () => {
window.sessionStorage.setItem('datastorePartialData', 'true');
const rejectResponse = {
data: null,
errors: [
Expand Down Expand Up @@ -317,7 +263,6 @@ describe('Sync', () => {
});

it('should send user agent suffix with graphql request', async () => {
window.sessionStorage.setItem('datastorePartialData', 'true');
const resolveResponse = {
data: {
syncPosts: {
Expand Down Expand Up @@ -377,7 +322,6 @@ describe('Sync', () => {
jest.resetModules();
jest.resetAllMocks();
errorHandler.mockClear();
window.sessionStorage.setItem('datastorePartialData', 'true');
});

test('bad record', async () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/datastore/src/datastore/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ import {
ManagedIdentifier,
PersistentModelMetaData,
IdentifierFieldOrIdentifierObject,
__modelMeta__,
isIdentifierObject,
AmplifyContext,
} from '../types';
// tslint:disable:no-duplicate-imports
import type { __modelMeta__ } from '../types';

import {
DATASTORE,
errorMessages,
Expand Down Expand Up @@ -309,7 +311,10 @@ const validateModelFields =
throw new Error(`Field ${name} is required`);
}

if (isSchemaModelWithAttributes(modelDefinition) && !isIdManaged(modelDefinition)) {
if (
isSchemaModelWithAttributes(modelDefinition) &&
!isIdManaged(modelDefinition)
) {
const keys = extractPrimaryKeyFieldNames(modelDefinition);
if (keys.includes(k) && v === '') {
logger.error(errorMessages.idEmptyString, { k, value: v });
Expand Down
4 changes: 3 additions & 1 deletion packages/datastore/src/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import {
AuthModeStrategy,
ManagedIdentifier,
OptionallyManagedIdentifier,
__modelMeta__,
AmplifyContext,
} from '../types';
// tslint:disable:no-duplicate-imports
import type { __modelMeta__ } from '../types';

import { exhaustiveCheck, getNow, SYNC, USER } from '../util';
import DataStoreConnectivity from './datastoreConnectivity';
import { ModelMerger } from './merger';
Expand Down
Loading

0 comments on commit bd5a9ad

Please sign in to comment.