Skip to content

Commit

Permalink
test: add tests for public items
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Jul 26, 2021
1 parent 6d185b0 commit 8d4c37a
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 68 deletions.
6 changes: 5 additions & 1 deletion cypress/fixtures/itemTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ export const ITEM_LOGIN_TAG = {
id: 'item-login-tag-id',
name: SETTINGS.ITEM_LOGIN.name,
};
export const ITEM_PUBLIC_TAG = {
id: 'public-tag-id',
name: SETTINGS.ITEM_PUBLIC.name,
};

export const DEFAULT_TAGS = [ITEM_LOGIN_TAG];
export const DEFAULT_TAGS = [ITEM_LOGIN_TAG, ITEM_PUBLIC_TAG];
152 changes: 151 additions & 1 deletion cypress/fixtures/items.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SETTINGS } from '../../src/config/constants';
import { ITEM_TYPES, PERMISSION_LEVELS } from '../../src/enums';
import { buildItemLoginSchemaExtra } from '../../src/utils/itemExtra';
import { DEFAULT_TAGS, ITEM_LOGIN_TAG } from './itemTags';
import { DEFAULT_TAGS, ITEM_LOGIN_TAG, ITEM_PUBLIC_TAG } from './itemTags';
import { CURRENT_USER, MEMBERS } from './members';

export const DEFAULT_FOLDER_ITEM = {
Expand Down Expand Up @@ -265,6 +265,156 @@ export const ITEM_LOGIN_ITEMS = {
tags: DEFAULT_TAGS,
};

export const SAMPLE_PUBLIC_ITEMS = {
items: [
{
...DEFAULT_FOLDER_ITEM,
id: 'ecafbd2a-5688-11eb-ae93-0242ac130002',
name: 'parent public item',
path: 'ecafbd2a_5688_11eb_ae93_0242ac130002',
extra: {
image: 'someimageurl',
},
tags: [
{
tagId: ITEM_PUBLIC_TAG.id,
itemPath: 'ecafbd2a_5688_11eb_ae93_0242ac130002',
},
],
memberships: [
{
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
{
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.READ,
memberId: MEMBERS.BOB.id,
},
],
},
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130002',
name: 'private item',
path: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
extra: {
image: 'someimageurl',
},
memberships: [
{
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
],
},
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130003',
name: 'child of public item',
path:
'ecafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130003',
extra: {
image: 'someimageurl',
},
memberships: [
{
itemId: 'fdf09f5a-5688-11eb-ae93-0242ac130003',
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130003',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
],
},
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130004',
name: 'public item',
path:
'ecafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130004',
extra: {
image: 'someimageurl',
},
tags: [
{
tagId: ITEM_PUBLIC_TAG.id,
itemPath:
'ecafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130004',
},
],
memberships: [
{
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
{
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.READ,
memberId: MEMBERS.BOB.id,
},
],
},
{
...DEFAULT_FOLDER_ITEM,
id: 'egafbd2a-5688-11eb-ae93-0242ac130002',
name: 'public item',
path: 'egafbd2a_5688_11eb_ae93_0242ac130002',
extra: {
image: 'someimageurl',
},
tags: [
{
tagId: ITEM_PUBLIC_TAG.id,
itemPath: 'egafbd2a_5688_11eb_ae93_0242ac130002',
},
],
memberships: [
{
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
],
},
{
...DEFAULT_FOLDER_ITEM,
id: 'bdf09f5a-5688-11eb-ae93-0242ac130004',
name: 'child of public item',
path:
'ecafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130004.bdf09f5a_5688_11eb_ae93_0242ac130004',
tags: [
{
tagId: ITEM_PUBLIC_TAG.id,
itemPath:
'ecafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130004',
},
],
memberships: [
{
itemId: 'bdf09f5a-5688-11eb-ae93-0242ac130004',
itemPath: 'bdf09f5a_5688_11eb_ae93_0242ac130004',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
],
},
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac133002',
name: 'child of private item',
path:
'fdf09f5a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac133002',
extra: {
image: 'someimageurl',
},
},
],
tags: DEFAULT_TAGS,
};

export const SHORTCUT = {
...DEFAULT_FOLDER_ITEM,
id: 'gcafbd2a-5688-11eb-ae92-0242ac130002',
Expand Down
2 changes: 2 additions & 0 deletions cypress/fixtures/members.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const SIGNED_OUT_MEMBER = {};

export const MEMBERS = {
ANNA: {
id: 'ecafbd2a-5642-31fb-ae93-0242ac130002',
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/authentication.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
USER_MENU_SIGN_OUT_OPTION_ID,
} from '../../src/config/selectors';
import { SAMPLE_ITEMS } from '../fixtures/items';
import { CURRENT_USER } from '../fixtures/members';
import { CURRENT_USER, SIGNED_OUT_MEMBER } from '../fixtures/members';
import {
REQUEST_FAILURE_LOADING_TIME,
PAGE_LOAD_WAITING_PAUSE,
Expand All @@ -24,7 +24,7 @@ import { REDIRECT_URL_LOCAL_STORAGE_KEY } from '../../src/config/constants';
describe('Authentication', () => {
describe('Signed Off > Redirect to sign in route', () => {
beforeEach(() => {
cy.setUpApi({ ...SAMPLE_ITEMS, getCurrentMemberError: true });
cy.setUpApi({ ...SAMPLE_ITEMS, currentMember: SIGNED_OUT_MEMBER });
});
it('Home', () => {
cy.visit(HOME_PATH);
Expand Down
6 changes: 3 additions & 3 deletions cypress/integration/item/itemLogin/itemLogin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '../../../../src/config/selectors';
import { getItemLoginExtra } from '../../../../src/utils/itemExtra';
import { ITEM_LOGIN_ITEMS } from '../../../fixtures/items';
import { MEMBERS } from '../../../fixtures/members';
import { MEMBERS, SIGNED_OUT_MEMBER } from '../../../fixtures/members';
import { ITEM_LOGIN_PAUSE } from '../../../support/constants';

const changeSignInMode = (mode) => {
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('Item Login', () => {

describe('User is signed out', () => {
beforeEach(() => {
cy.setUpApi({ ...ITEM_LOGIN_ITEMS, getCurrentMemberError: true });
cy.setUpApi({ ...ITEM_LOGIN_ITEMS, currentMember: SIGNED_OUT_MEMBER });
});

describe('Display Item Login Screen', () => {
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('Item Login', () => {
cy.setUpApi({
...ITEM_LOGIN_ITEMS,
postItemLoginError: true,
getCurrentMemberError: true,
currentMember: SIGNED_OUT_MEMBER,
});
const { id } = ITEM_LOGIN_ITEMS.items[4];

Expand Down
123 changes: 123 additions & 0 deletions cypress/integration/item/public/publicItems.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { buildItemPath } from '../../../../src/config/paths';
import {
ITEM_LOGIN_SCREEN_FORBIDDEN_ID,
ITEM_SETTINGS_BUTTON_CLASS,
PUBLIC_SETTING_SWITCH_ID,
} from '../../../../src/config/selectors';
import { SAMPLE_PUBLIC_ITEMS } from '../../../fixtures/items';
import { ITEM_PUBLIC_TAG } from '../../../fixtures/itemTags';
import { MEMBERS, SIGNED_OUT_MEMBER } from '../../../fixtures/members';
import { expectFolderViewScreenLayout } from '../view/utils';

const checkPublicLoginSetting = ({ isEnabled, disabled = false }) => {
const checkedValue = isEnabled ? 'be.checked' : 'not.be.checked';
cy.get(`#${PUBLIC_SETTING_SWITCH_ID}`).should(checkedValue);
if (disabled) {
cy.get(`#${PUBLIC_SETTING_SWITCH_ID}`).should('be.disabled');
}
};

const editPublicSetting = (isEnabled) => {
if (isEnabled) {
cy.get(`#${PUBLIC_SETTING_SWITCH_ID}`).check();
} else {
cy.get(`#${PUBLIC_SETTING_SWITCH_ID}`).uncheck();
}
cy.wait('@postItemTag').then(({ response: { body } }) => {
expect(body?.tagId).to.equal(ITEM_PUBLIC_TAG.id);
});
};

describe('Public Items', () => {
describe('Setting', () => {
it('Successfully enable Public Setting', () => {
cy.setUpApi(SAMPLE_PUBLIC_ITEMS);
const item = SAMPLE_PUBLIC_ITEMS.items[1];
cy.visit(buildItemPath(item.id));
cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click();

// set public a private folder
checkPublicLoginSetting({ isEnabled: false });
editPublicSetting(true);
});
});

describe('Enabled', () => {
it('Signed out user can access a public item', () => {
const currentMember = SIGNED_OUT_MEMBER;
cy.setUpApi({
...SAMPLE_PUBLIC_ITEMS,
currentMember,
});
const item = SAMPLE_PUBLIC_ITEMS.items[4];
cy.visit(buildItemPath(item.id));
cy.wait('@getPublicItem');
cy.wait('@getPublicChildren');
expectFolderViewScreenLayout({ item, currentMember });
});

it('User without a membership can access a public item', () => {
const currentMember = MEMBERS.BOB;
cy.setUpApi({
...SAMPLE_PUBLIC_ITEMS,
currentMember,
});
const item = SAMPLE_PUBLIC_ITEMS.items[4];
cy.visit(buildItemPath(item.id));
cy.wait('@getPublicItem');
cy.wait('@getPublicChildren');
expectFolderViewScreenLayout({ item, currentMember });
});

it('User without a membership can access a child of a public item', () => {
const currentMember = MEMBERS.BOB;
cy.setUpApi({
...SAMPLE_PUBLIC_ITEMS,
currentMember,
});
const item = SAMPLE_PUBLIC_ITEMS.items[2];
cy.visit(buildItemPath(item.id));
cy.wait('@getPublicItem');
cy.wait('@getPublicChildren');
expectFolderViewScreenLayout({ item, currentMember });
});
});

describe('Disabled', () => {
it('Signed out user cannot access a private item', () => {
const currentMember = SIGNED_OUT_MEMBER;
cy.setUpApi({
...SAMPLE_PUBLIC_ITEMS,
currentMember,
});
const item = SAMPLE_PUBLIC_ITEMS.items[1];
cy.visit(buildItemPath(item.id));
cy.wait('@getPublicItem');
cy.get(`#${ITEM_LOGIN_SCREEN_FORBIDDEN_ID}`).should('exist');
});

it('User without a membership cannot access a private item', () => {
const currentMember = MEMBERS.BOB;
cy.setUpApi({
...SAMPLE_PUBLIC_ITEMS,
currentMember,
});
const item = SAMPLE_PUBLIC_ITEMS.items[1];
cy.visit(buildItemPath(item.id));
cy.wait('@getPublicItem');
cy.get(`#${ITEM_LOGIN_SCREEN_FORBIDDEN_ID}`).should('exist');
});

it('User without a membership cannot access a child of a private item', () => {
const currentMember = MEMBERS.BOB;
cy.setUpApi({
...SAMPLE_PUBLIC_ITEMS,
currentMember,
});
const item = SAMPLE_PUBLIC_ITEMS.items[6];
cy.visit(buildItemPath(item.id));
cy.wait('@getPublicItem');
cy.get(`#${ITEM_LOGIN_SCREEN_FORBIDDEN_ID}`).should('exist');
});
});
});
Loading

0 comments on commit 8d4c37a

Please sign in to comment.