Skip to content

Commit

Permalink
feat(oauth): add anonymous test caes for auth
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Sep 4, 2020
1 parent 4974d4f commit 2abc2fd
Showing 1 changed file with 74 additions and 9 deletions.
83 changes: 74 additions & 9 deletions src/types/__test__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const mutationLevel3Scope = ['mutation:level3']
const VIEWER_SCOPED_PRIVATE = `
query ($input: UserInput!) {
viewer {
id
displayName
likerId
info {
Expand Down Expand Up @@ -142,7 +143,71 @@ const prepare = async ({
*
* mode: 'visitor'
*/
// TODO
describe('Anonymous query and mutation', () => {
test('query with public and private fields', async () => {
const { query } = await testClient({ isAuth: false })
const otherUserName = 'test2'
const { data } = await query({
query: VIEWER_SCOPED_PRIVATE,
variables: { input: { userName: otherUserName } },
})
expect(data && data.viewer.id).toBe('')
expect(data && data.viewer.displayName).toBe(null)
expect(data && data.viewer.info.email).toBe(null)
expect(data && data.user.displayName).toBe(otherUserName)
})

test('query with private fields', async () => {
const { query } = await testClient({ isAuth: false })
const otherUserName = 'test2'
const error_case = await query({
query: VIEWER_SCOPED_WITH_OTHER_PRIVATE,
variables: { input: { userName: otherUserName } },
})
expect(_.get(error_case, 'errors.length')).toBe(1)
expect(_.get(error_case, 'errors.0.message')).toBeTruthy()
})

test('query nested other private fields', async () => {
const { query } = await testClient({ isAuth: false })
const errorCase1 = await query({ query: VIEWER_NESTED_OTHER_PARIVATE })
expect(errorCase1 && errorCase1.errors && errorCase1.errors.length).toBe(1)
expect(
errorCase1 && errorCase1.errors && errorCase1.errors[0].message
).toBeTruthy()
})

test('level1 mutation', async () => {
const description = 'foo bar'
const { mutate } = await testClient({ isAuth: false })
const { errors } = await mutate({
mutation: UPDATE_USER_INFO_DESCRIPTION,
variables: { input: { description } },
})
expect(errors && errors.length).toBe(1)
expect(errors && errors[0].message).toBeTruthy()
})

test('level2 mutation', async () => {
const content = 'test comment content'
const { mutate } = await testClient({ isAuth: false })
const { errors } = await mutate({
mutation: CREATE_COMMENT,
variables: { content },
})
expect(errors && errors.length).toBe(1)
expect(errors && errors[0].message).toBeTruthy()
})

test('level3 mutation', async () => {
const { mutate } = await testClient({ isAuth: false })
const { errors } = await mutate({
mutation: CLEAR_SEARCH_HISTORY,
})
expect(errors && errors.length).toBe(1)
expect(errors && errors[0].message).toBeTruthy()
})
})

/**
* Check OAuth viewer query and mutation are functional or not.
Expand Down Expand Up @@ -351,21 +416,21 @@ describe('General viewer query and mutation', () => {

test('level2 mutation', async () => {
const content = 'test comment content'
const { mutate: scopedMutate } = await prepare({
const { mutate } = await prepare({
email: defaultTestUser.email,
})
const { data } = await scopedMutate({
const { data } = await mutate({
mutation: CREATE_COMMENT,
variables: { content },
})
expect(_.get(data, 'putComment.content')).toBe(content)
})

test('level3 mutation', async () => {
const { mutate: scopedMutate } = await prepare({
const { mutate } = await prepare({
email: defaultTestUser.email,
})
const { data } = await scopedMutate({
const { data } = await mutate({
mutation: CLEAR_SEARCH_HISTORY,
})
expect(data?.clearSearchHistory).toBeTruthy()
Expand Down Expand Up @@ -431,21 +496,21 @@ describe('Admin viewer query and mutation', () => {

test('level2 mutation', async () => {
const content = 'test comment content'
const { mutate: scopedMutate } = await prepare({
const { mutate } = await prepare({
email: adminUser.email,
})
const { data } = await scopedMutate({
const { data } = await mutate({
mutation: CREATE_COMMENT,
variables: { content },
})
expect(_.get(data, 'putComment.content')).toBe(content)
})

test('level3 mutation', async () => {
const { mutate: scopedMutate } = await prepare({
const { mutate } = await prepare({
email: adminUser.email,
})
const { data } = await scopedMutate({
const { data } = await mutate({
mutation: CLEAR_SEARCH_HISTORY,
})
expect(data?.clearSearchHistory).toBeTruthy()
Expand Down

0 comments on commit 2abc2fd

Please sign in to comment.