Skip to content
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

Added ES e2e deletePost and updatePost tests. Also making the tests stack names unique per execution. #5

Merged
merged 9 commits into from
Aug 24, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import AppSyncTransformer from 'graphql-appsync-transformer'
import { CloudFormationClient } from '../CloudFormationClient'
import { Output } from 'aws-sdk/clients/cloudformation'
import { GraphQLClient } from '../GraphQLClient'
import * as moment from 'moment';
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we previously depend on moment? If not there needs to be an update to package.json devDependencies for all these packages.

Copy link
Author

Choose a reason for hiding this comment

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

I added moment dependency for ES tests that got merged like a couple of days ago.


jest.setTimeout(200000);

const cf = new CloudFormationClient('us-west-2')
const STACK_NAME = 'DynamoDBModelTransformerTest'

const dateAppender = moment().format('YYYYMMDDHHmmss')
const STACK_NAME = `DynamoDBModelTransformerTest-${dateAppender}`

let GRAPHQL_CLIENT = undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ import AppSyncTransformer from 'graphql-appsync-transformer'
import { S3Client } from '../S3Client';
import * as path from 'path'
import { deploy } from '../deploy'
import * as moment from 'moment';

// to deal with bug in cognito-identity-js
(global as any).fetch = require("node-fetch");

jest.setTimeout(1000000);

const cf = new CloudFormationClient('us-west-2')
const STACK_NAME = 'ModelAuthTransformerTest'

const dateAppender = moment().format('YYYYMMDDHHmmss')
const STACK_NAME = `ModelAuthTransformerTest-${dateAppender}`

let GRAPHQL_ENDPOINT = undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import ModelConnectionTransformer from 'graphql-connection-transformer'
import { CloudFormationClient } from '../CloudFormationClient'
import { Output } from 'aws-sdk/clients/cloudformation'
import { GraphQLClient } from '../GraphQLClient'
import * as moment from 'moment';

jest.setTimeout(2000000);

const cf = new CloudFormationClient('us-west-2')
const STACK_NAME = 'ModelConnectionTransformerTest'

const dateAppender = moment().format('YYYYMMDDHHmmss')
const STACK_NAME = `ModelConnectionTransformerTest-${dateAppender}`

let GRAPHQL_CLIENT = undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ test('Test searchPosts query without filter', async () => {
searchPosts {
items { ...FullPost }
}
}`, 'Test searchPosts response without filter: ')
}`, 'Test searchPosts response without filter response: ')
expect(response).toBeDefined
expect(response.data.searchPosts.items).toBeDefined
const items = response.data.searchPosts.items
Expand All @@ -175,7 +175,7 @@ test('Test searchPosts query with basic filter', async () => {
}) {
items { ...FullPost }
}
}`, 'Test searchPosts response with basic filter: ')
}`, 'Test searchPosts response with basic filter response: ')
expect(response).toBeDefined
expect(response.data.searchPosts.items).toBeDefined
const items = response.data.searchPosts.items
Expand All @@ -194,11 +194,12 @@ test('Test searchPosts query with non-recursive filter', async () => {
}) {
items { ...FullPost }
}
}`, 'Test searchPosts response with non-recursive filter: ')
}`, 'Test searchPosts response with non-recursive filter response: ')
expect(response).toBeDefined
expect(response.data.searchPosts.items).toBeDefined
const items = response.data.searchPosts.items
expect(items.length).toEqual(1)
expect(items[0].id).toBeDefined()
expect(items[0].author).toEqual("snvishna")
expect(items[0].title).toEqual("test title")
expect(items[0].ups).toEqual(170)
Expand All @@ -223,11 +224,12 @@ test('Test searchPosts query with recursive filter 1', async () => {
}) {
items { ...FullPost }
}
}`, 'Test searchPosts response with recursive filter 1: ')
}`, 'Test searchPosts response with recursive filter 1 response: ')
expect(response).toBeDefined
expect(response.data.searchPosts.items).toBeDefined
const items = response.data.searchPosts.items
expect(items.length).toEqual(1)
expect(items[0].id).toBeDefined()
expect(items[0].author).toEqual("snvishna")
expect(items[0].title).toEqual("test")
expect(items[0].ups).toEqual(157)
Expand All @@ -252,7 +254,7 @@ test('Test searchPosts query with recursive filter 2', async () => {
}) {
items { ...FullPost }
}
}`, 'Test searchPosts response with recursive filter 2: ')
}`, 'Test searchPosts response with recursive filter 2 response: ')
expect(response).toBeDefined
expect(response.data.searchPosts.items).toBeDefined
const items = response.data.searchPosts.items
Expand Down Expand Up @@ -281,11 +283,12 @@ test('Test searchPosts query with recursive filter 3', async () => {
}) {
items { ...FullPost }
}
}`, 'Test searchPosts query with recursive filter 3: ')
}`, 'Test searchPosts query with recursive filter 3 response: ')
expect(response).toBeDefined
expect(response.data.searchPosts.items).toBeDefined
const items = response.data.searchPosts.items
expect(items.length).toEqual(1)
expect(items[0].id).toBeDefined()
expect(items[0].author).toEqual("snvishna")
expect(items[0].title).toEqual("test title")
expect(items[0].ups).toEqual(200)
Expand Down Expand Up @@ -319,11 +322,12 @@ test('Test searchPosts query with recursive filter 4', async () => {
}) {
items { ...FullPost }
}
}`, 'Test searchPosts query with recursive filter 4: ')
}`, 'Test searchPosts query with recursive filter 4 response: ')
expect(response).toBeDefined
expect(response.data.searchPosts.items).toBeDefined
const items = response.data.searchPosts.items
expect(items.length).toEqual(1)
expect(items[0].id).toBeDefined()
expect(items[0].author).toEqual("snvishna")
expect(items[0].title).toEqual("test title")
expect(items[0].ups).toEqual(160)
Expand Down Expand Up @@ -357,11 +361,12 @@ test('Test searchPosts query with recursive filter 5', async () => {
}) {
items { ...FullPost }
}
}`, 'Test searchPosts query with recursive filter 5: ')
}`, 'Test searchPosts query with recursive filter 5 response: ')
expect(response).toBeDefined
expect(response.data.searchPosts.items).toBeDefined
const items = response.data.searchPosts.items
expect(items.length).toEqual(1)
expect(items[0].id).toBeDefined()
expect(items[0].author).toEqual("snvishna")
expect(items[0].title).toEqual("test title")
expect(items[0].ups).toEqual(200)
Expand Down Expand Up @@ -394,13 +399,154 @@ test('Test searchPosts query with recursive filter 6', async () => {
}) {
items { ...FullPost }
}
}`, 'Test searchPosts query with recursive filter 6: ')
}`, 'Test searchPosts query with recursive filter 6 response: ')
expect(response).toBeDefined
expect(response.data.searchPosts.items).toBeDefined
const items = response.data.searchPosts.items
expect(items.length).toEqual(0)
})

test('Test deletePosts syncing with Elasticsearch', async () => {
// Create Post
const title = 'to be deleted';
const postToBeDeletedResponse = await runQuery(getCreatePostsQuery(
"test author new", title, 1157, 1000, 22.2, true
), 'createPost (to be deleted) response: ');
expect(postToBeDeletedResponse).toBeDefined
expect(postToBeDeletedResponse.data.createPost).toBeDefined
expect(postToBeDeletedResponse.data.createPost.id).toBeDefined()

// Wait for the Post to sync to Elasticsearch
await cf.wait(10, () => Promise.resolve())

const searchResponse1 = await runQuery(`query {
searchPosts(filter: {
title: { eq: "${title}" }
}) {
items { ...FullPost }
}
}`, 'Test deletePosts syncing with Elasticsearch Search_Before response: ')
expect(searchResponse1).toBeDefined
expect(searchResponse1.data.searchPosts.items).toBeDefined
const items1 = searchResponse1.data.searchPosts.items
expect(items1.length).toEqual(1)
expect(items1[0].id).toEqual(postToBeDeletedResponse.data.createPost.id)
expect(items1[0].author).toEqual("test author new")
expect(items1[0].title).toEqual(title)
expect(items1[0].ups).toEqual(1157)
expect(items1[0].downs).toEqual(1000)
expect(items1[0].percentageUp).toEqual(22.2)
expect(items1[0].isPublished).toEqual(true)

const deleteResponse = await runQuery(`mutation {
deletePost(input: {
id: "${postToBeDeletedResponse.data.createPost.id}"
}) {
...FullPost
}
}`, 'Test deletePosts syncing with Elasticsearch Perform_Delete response: ')
expect(deleteResponse).toBeDefined
expect(deleteResponse.data.deletePost).toBeDefined
expect(deleteResponse.data.deletePost.id).toEqual(postToBeDeletedResponse.data.createPost.id)

// Wait for the Deleted Post to sync to Elasticsearch
await cf.wait(10, () => Promise.resolve())

const searchResponse2 = await runQuery(`query {
searchPosts(filter: {
title: { eq: "${title}" }
}) {
items { ...FullPost }
}
}`, 'Test deletePosts syncing with Elasticsearch Search_After response: ')
expect(searchResponse2).toBeDefined
expect(searchResponse2.data.searchPosts.items).toBeDefined
const items2 = searchResponse2.data.searchPosts.items
expect(items2.length).toEqual(0)
})

test('Test updatePost syncing with Elasticsearch', async () => {
// Create Post
const author = 'test author update new';
const title = 'to be updated new';
const ups = 2157;
const downs = 2000;
const percentageUp = 22.2;
const isPublished = true;

const postToBeUpdatedResponse = await runQuery(getCreatePostsQuery(
author, title, ups, downs, percentageUp, isPublished
), 'createPost (to be updated) response: ');
expect(postToBeUpdatedResponse).toBeDefined;
expect(postToBeUpdatedResponse.data.createPost).toBeDefined;

const id = postToBeUpdatedResponse.data.createPost.id;
expect(id).toBeDefined()

// Wait for the Post to sync to Elasticsearch
await cf.wait(10, () => Promise.resolve())

const searchResponse1 = await runQuery(`query {
searchPosts(filter: {
id: { eq: "${id}" }
}) {
items { ...FullPost }
}
}`, 'Test updatePost syncing with Elasticsearch Search_Before response: ')
expect(searchResponse1).toBeDefined;
expect(searchResponse1.data.searchPosts.items).toBeDefined;
const items1 = searchResponse1.data.searchPosts.items;
expect(items1.length).toEqual(1);
expect(items1[0].id).toEqual(id);
expect(items1[0].author).toEqual(author);
expect(items1[0].title).toEqual(title);
expect(items1[0].ups).toEqual(ups);
expect(items1[0].downs).toEqual(downs);
expect(items1[0].percentageUp).toEqual(percentageUp);
expect(items1[0].isPublished).toEqual(isPublished);

const newTitle = title.concat('_updated');
const updateResponse = await runQuery(`mutation {
updatePost(input: {
id: "${id}"
author: "${author}"
title: "${newTitle}"
ups: ${ups}
downs: ${downs}
percentageUp: ${percentageUp}
isPublished: ${isPublished}
}) {
...FullPost
}
}`, 'Test updatePost syncing with Elasticsearch Perform_Update response: ')
expect(updateResponse).toBeDefined
expect(updateResponse.data.updatePost).toBeDefined
expect(updateResponse.data.updatePost.id).toEqual(id)
expect(updateResponse.data.updatePost.title).toEqual(newTitle)

// Wait for the Update Post to sync to Elasticsearch
await cf.wait(10, () => Promise.resolve())

const searchResponse2 = await runQuery(`query {
searchPosts(filter: {
id: { eq: "${id}" }
}) {
items { ...FullPost }
}
}`, 'Test updatePost syncing with Elasticsearch Search_After response: ')
expect(searchResponse2).toBeDefined;
expect(searchResponse2.data.searchPosts.items).toBeDefined;
const items2 = searchResponse2.data.searchPosts.items;
expect(items2.length).toEqual(1);
expect(items2[0].id).toEqual(id);
expect(items2[0].author).toEqual(author);
expect(items2[0].title).toEqual(newTitle);
expect(items2[0].ups).toEqual(ups);
expect(items2[0].downs).toEqual(downs);
expect(items2[0].percentageUp).toEqual(percentageUp);
expect(items2[0].isPublished).toEqual(isPublished);
})

function generateParams() {
const params = {
[ResourceConstants.PARAMETERS.ElasticSearchStreamingLambdaCodeS3Bucket]: BUCKET_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import VersionedModelTransformer from 'graphql-versioned-transformer'
import { CloudFormationClient } from '../CloudFormationClient'
import { Output } from 'aws-sdk/clients/cloudformation'
import { GraphQLClient } from '../GraphQLClient'
import * as moment from 'moment';

jest.setTimeout(200000);

const cf = new CloudFormationClient('us-west-2')
const STACK_NAME = 'GraphQLVersionedTest'

const dateAppender = moment().format('YYYYMMDDHHmmss')
const STACK_NAME = `GraphQLVersionedTest-${dateAppender}`

let GRAPHQL_CLIENT = undefined;

Expand Down