Skip to content

Commit

Permalink
style: run prettier through code
Browse files Browse the repository at this point in the history
  • Loading branch information
SwaySway authored and yuth committed Oct 10, 2019
1 parent 6481db0 commit 18f04d1
Show file tree
Hide file tree
Showing 474 changed files with 48,425 additions and 44,236 deletions.
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: ['@commitlint/config-lerna-scopes', '@commitlint/config-conventional']
extends: ['@commitlint/config-lerna-scopes', '@commitlint/config-conventional'],
};
37 changes: 20 additions & 17 deletions cypress/integration/api_spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@

describe('API test post and get', function() {
beforeEach(function() {
cy.visit('/')
})

it('successfully adds data to dynamodb', function() {
// Check for user not signed up
cy.get('input[name=itemNo]').type('1')
cy.get('.amplify-submit-put-button').contains('Put').click()
cy.get('.amplify-put-result').contains('post call succeed!')
})
beforeEach(function() {
cy.visit('/');
});

it('successfully adds data to dynamodb', function() {
// Check for user not signed up
cy.get('input[name=itemNo]').type('1');
cy.get('.amplify-submit-put-button')
.contains('Put')
.click();
cy.get('.amplify-put-result').contains('post call succeed!');
});

it('successfully get data from dynamodb', function() {
// Check for user not signed up
cy.get('.amplify-submit-get-button').contains('Get').click()
cy.get('.amplify-get-result').contains('"itemNo":1')
})
})
it('successfully get data from dynamodb', function() {
// Check for user not signed up
cy.get('.amplify-submit-get-button')
.contains('Get')
.click();
cy.get('.amplify-get-result').contains('"itemNo":1');
});
});
20 changes: 10 additions & 10 deletions cypress/integration/auth_spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

describe('withAuthenticator Sign In', function() {
beforeEach(function() {
cy.visit('/')
})
cy.visit('/');
});

it('throws error when user is not signed up', function() {
// Check for user not signed up
cy.get('input[name=username]').type('testuser')
cy.get('input[name=password]').type('testPassword')
cy.get('button').contains('Sign In').click()
cy.get('div').contains('User does not exist')
})
})

cy.get('input[name=username]').type('testuser');
cy.get('input[name=password]').type('testPassword');
cy.get('button')
.contains('Sign In')
.click();
cy.get('div').contains('User does not exist');
});
});
2 changes: 1 addition & 1 deletion cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
};
2 changes: 1 addition & 1 deletion cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,25 @@ describe('Velocity $context.util.time', () => {
});

it('parseFormattedToEpochMilliSeconds', () => {
expect(
time.parseFormattedToEpochMilliSeconds(TEST_TIMESTAMP_CUSTOM_UTC, FORMAT_CUSTOM_ZONED)
).toEqual(TEST_TIMESTAMP_MILLIS);
expect(
time.parseFormattedToEpochMilliSeconds(TEST_TIMESTAMP_CUSTOM_PLUS8, FORMAT_CUSTOM_ZONED)
).toEqual(TEST_TIMESTAMP_MILLIS);
expect(
time.parseFormattedToEpochMilliSeconds(TEST_TIMESTAMP_CUSTOM_UTC, FORMAT_CUSTOM_ZONED)
).toEqual(TEST_TIMESTAMP_MILLIS);
expect(
time.parseFormattedToEpochMilliSeconds(
TEST_TIMESTAMP_CUSTOM_PLUS8,
FORMAT_CUSTOM_ZONED,
'Australia/Perth'
)
).toEqual(TEST_TIMESTAMP_MILLIS);
expect(
time.parseFormattedToEpochMilliSeconds(
TEST_TIMESTAMP_CUSTOM_UTC_UNZONED,
FORMAT_CUSTOM_UNZONED,
'UTC'
)
).toEqual(TEST_TIMESTAMP_MILLIS);

expect(
time.parseFormattedToEpochMilliSeconds(
TEST_TIMESTAMP_CUSTOM_PLUS8_UNZONED,
FORMAT_CUSTOM_UNZONED,
'Australia/Perth'
)
).toEqual(TEST_TIMESTAMP_MILLIS);
});

it('parseISO8601ToEpochMilliSeconds', () => {
expect(time.parseISO8601ToEpochMilliSeconds(TEST_TIMESTAMP_ZULU)).toEqual(
expect(time.parseFormattedToEpochMilliSeconds(TEST_TIMESTAMP_CUSTOM_UTC, FORMAT_CUSTOM_ZONED)).toEqual(TEST_TIMESTAMP_MILLIS);
expect(time.parseFormattedToEpochMilliSeconds(TEST_TIMESTAMP_CUSTOM_PLUS8, FORMAT_CUSTOM_ZONED)).toEqual(TEST_TIMESTAMP_MILLIS);
expect(time.parseFormattedToEpochMilliSeconds(TEST_TIMESTAMP_CUSTOM_UTC, FORMAT_CUSTOM_ZONED)).toEqual(TEST_TIMESTAMP_MILLIS);
expect(time.parseFormattedToEpochMilliSeconds(TEST_TIMESTAMP_CUSTOM_PLUS8, FORMAT_CUSTOM_ZONED, 'Australia/Perth')).toEqual(
TEST_TIMESTAMP_MILLIS
);
expect(time.parseFormattedToEpochMilliSeconds(TEST_TIMESTAMP_CUSTOM_UTC_UNZONED, FORMAT_CUSTOM_UNZONED, 'UTC')).toEqual(
TEST_TIMESTAMP_MILLIS
);
expect(time.parseISO8601ToEpochMilliSeconds(TEST_TIMESTAMP_PLUS8)).toEqual(

expect(time.parseFormattedToEpochMilliSeconds(TEST_TIMESTAMP_CUSTOM_PLUS8_UNZONED, FORMAT_CUSTOM_UNZONED, 'Australia/Perth')).toEqual(
TEST_TIMESTAMP_MILLIS
);
});

it('parseISO8601ToEpochMilliSeconds', () => {
expect(time.parseISO8601ToEpochMilliSeconds(TEST_TIMESTAMP_ZULU)).toEqual(TEST_TIMESTAMP_MILLIS);
expect(time.parseISO8601ToEpochMilliSeconds(TEST_TIMESTAMP_PLUS8)).toEqual(TEST_TIMESTAMP_MILLIS);
});
it('epochMilliSecondsToSeconds', () => {
expect(time.epochMilliSecondsToSeconds(TEST_TIMESTAMP_MILLIS)).toEqual(TEST_TIMESTAMP_SECS);
});
Expand All @@ -86,16 +64,10 @@ describe('Velocity $context.util.time', () => {
});

it('epochMilliSecondsToFormatted', () => {
expect(time.epochMilliSecondsToFormatted(TEST_TIMESTAMP_MILLIS, FORMAT_CUSTOM_ZONED)).toEqual(
TEST_TIMESTAMP_CUSTOM_UTC
);
expect(time.epochMilliSecondsToFormatted(TEST_TIMESTAMP_MILLIS, FORMAT_CUSTOM_ZONED)).toEqual(TEST_TIMESTAMP_CUSTOM_UTC);

expect(
time.epochMilliSecondsToFormatted(
TEST_TIMESTAMP_MILLIS,
FORMAT_CUSTOM_ZONED,
'Australia/Perth'
)
).toEqual(TEST_TIMESTAMP_CUSTOM_PLUS8);
expect(time.epochMilliSecondsToFormatted(TEST_TIMESTAMP_MILLIS, FORMAT_CUSTOM_ZONED, 'Australia/Perth')).toEqual(
TEST_TIMESTAMP_CUSTOM_PLUS8
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ describe('JavaMap', () => {
it('entrySet', () => {
const obj = { foo: 'Foo Value', bar: 'Bar Value' };
const map = new JavaMap(obj, identityMapper);
expect(map.entrySet().toJSON()).toEqual([
{ key: 'foo', value: 'Foo Value' },
{ key: 'bar', value: 'Bar Value' },
]);
expect(map.entrySet().toJSON()).toEqual([{ key: 'foo', value: 'Foo Value' }, { key: 'bar', value: 'Bar Value' }]);
});

it('equal', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { JavaString } from '../../../velocity/value-mapper/string';

describe('JavaString', () => {
it('replaceAll', () => {
const str = new JavaString('foo bar foo bar foo bar Foo')
const str = new JavaString('foo bar foo bar foo bar Foo');
const replacedStr = str.replaceAll('foo', 'baz');
expect(replacedStr.toString()).toEqual('baz bar baz bar baz bar Foo');
expect(replacedStr.toIdString()).toEqual('baz bar baz bar baz bar Foo');
expect(replacedStr.toJSON()).toEqual('baz bar baz bar baz bar Foo');
})
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Velocity - ValueMapper toJSON', () => {
it('should not call toJSON if the object is null', () => {
expect(toJSON(null)).toEqual(null);
});

it('should return the source object if it doesnot implement toJSON', () => {
const testObj = {
foo: 'Foo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,7 @@ export class DynamoDBDataLoader implements AmplifyAppSyncSimulatorDataLoader {

return this.getItem({ key, consistentRead: true });
}
private async query({
query: keyCondition,
filter,
index,
nextToken,
limit,
scanIndexForward = true,
consistentRead = false,
select,
}) {
private async query({ query: keyCondition, filter, index, nextToken, limit, scanIndexForward = true, consistentRead = false, select }) {
keyCondition = keyCondition || { expression: null };
filter = filter || { expression: null };
const params = {
Expand All @@ -133,18 +124,14 @@ export class DynamoDBDataLoader implements AmplifyAppSyncSimulatorDataLoader {
ScanIndexForward: scanIndexForward,
Select: select || 'ALL_ATTRIBUTES',
};
const {
Items: items,
ScannedCount: scannedCount,
LastEvaluatedKey: resultNextToken = null,
} = await this.client.query(params as any).promise();
const { Items: items, ScannedCount: scannedCount, LastEvaluatedKey: resultNextToken = null } = await this.client
.query(params as any)
.promise();

return {
items: items.map(item => unmarshall(item)),
scannedCount,
nextToken: resultNextToken
? Buffer.from(JSON.stringify(resultNextToken)).toString('base64')
: null,
nextToken: resultNextToken ? Buffer.from(JSON.stringify(resultNextToken)).toString('base64') : null,
};
}

Expand Down Expand Up @@ -194,16 +181,7 @@ export class DynamoDBDataLoader implements AmplifyAppSyncSimulatorDataLoader {
return unmarshall(deleted);
}
private async scan(payload) {
const {
filter,
index,
limit,
consistentRead = false,
nextToken,
select,
totalSegments,
segment,
} = payload;
const { filter, index, limit, consistentRead = false, nextToken, select, totalSegments, segment } = payload;

const params = {
TableName: this.tableName,
Expand All @@ -226,18 +204,12 @@ export class DynamoDBDataLoader implements AmplifyAppSyncSimulatorDataLoader {
},
});
}
const {
Items: items,
ScannedCount: scannedCount,
LastEvaluatedKey: resultNextToken = null,
} = await this.client.scan(params).promise();
const { Items: items, ScannedCount: scannedCount, LastEvaluatedKey: resultNextToken = null } = await this.client.scan(params).promise();

return {
items: items.map(item => unmarshall(item)),
scannedCount,
nextToken: resultNextToken
? Buffer.from(JSON.stringify(resultNextToken)).toString('base64')
: null,
nextToken: resultNextToken ? Buffer.from(JSON.stringify(resultNextToken)).toString('base64') : null,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function unmarshall(raw, isRaw: boolean = true) {
...sum,
[key]: unmarshall(value, false),
}),
{},
{}
);
}

Expand Down
18 changes: 5 additions & 13 deletions packages/amplify-appsync-simulator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class AmplifyAppSyncSimulator {
serverConfig: AppSyncSimulatorServerConfig = {
port: 0,
wsPort: 0,
},
}
) {
this._serverConfig = serverConfig;
this._pubsub = new PubSub();
Expand Down Expand Up @@ -77,11 +77,7 @@ export class AmplifyAppSyncSimulator {
}, new Map());

this.functions = (config.functions || []).reduce((map, fn) => {
const {
dataSourceName,
requestMappingTemplateLocation,
responseMappingTemplateLocation,
} = fn;
const { dataSourceName, requestMappingTemplateLocation, responseMappingTemplateLocation } = fn;
map.set(
fn.name,
new AmplifySimulatorFunction(
Expand All @@ -90,8 +86,8 @@ export class AmplifyAppSyncSimulator {
requestMappingTemplateLocation: requestMappingTemplateLocation,
responseMappingTemplateLocation: responseMappingTemplateLocation,
},
this,
),
this
)
);
return map;
}, new Map());
Expand All @@ -109,11 +105,7 @@ export class AmplifyAppSyncSimulator {
return map;
}, new Map());

this._schema = generateResolvers(
new Source(config.schema.content, config.schema.path),
config.resolvers,
this,
);
this._schema = generateResolvers(new Source(config.schema.content, config.schema.path), config.resolvers, this);
this._config = config;
} catch (e) {
this._schema = lastSchema;
Expand Down
7 changes: 1 addition & 6 deletions packages/amplify-appsync-simulator/src/mqtt-server/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,7 @@ export class Client {
}

// skip delivery of messages in $SYS for wildcards
forward =
forward &&
!(
topic.indexOf('$SYS') >= 0 &&
((indexWildcard >= 0 && indexWildcard < 2) || (indexPlus >= 0 && indexPlus < 2))
);
forward = forward && !(topic.indexOf('$SYS') >= 0 && ((indexWildcard >= 0 && indexWildcard < 2) || (indexPlus >= 0 && indexPlus < 2)));

if (forward) {
if (options._dedupId === undefined) {
Expand Down
5 changes: 2 additions & 3 deletions packages/amplify-appsync-simulator/src/mqtt-server/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export function defer (done) {
if (typeof done === "function") {
export function defer(done) {
if (typeof done === 'function') {
setImmediate(done);
}
}

Loading

0 comments on commit 18f04d1

Please sign in to comment.