diff --git a/build-tests/Makefile b/build-tests/Makefile index 715d902dd0..f44ee5dee4 100644 --- a/build-tests/Makefile +++ b/build-tests/Makefile @@ -1,10 +1,9 @@ build: npm install -test: - ./node_modules/.bin/ava --verbose --concurrency=3 > results.txt 2>&1 +test-bvt: + rm -rf allure-report allure-results + ./node_modules/mocha/bin/mocha --compilers js:babel-core/register 'test/*' --reporter mocha-allure-reporter report: - rm -rf allure-report allure-results - node make-allure-report.js results.txt allure generate allure-results diff --git a/build-tests/README.md b/build-tests/README.md new file mode 100644 index 0000000000..d8fb0bac56 --- /dev/null +++ b/build-tests/README.md @@ -0,0 +1,78 @@ +# build-tests + +API based tests automation framework, initially created for running build verification test suite. +The goal of BVT as a test suite is to run sanity checks to make sure build is OK. + +#### Installation + +Install dependencies: + + npm install + +Install Allure CLI. + +Ubuntu: + + sudo apt-add-repository ppa:yandex-qatools/allure-framework + sudo apt-get update + sudo apt-get install allure-commandline + +MacOS: + + brew tap qatools/formulas + brew install allure-commandline + +Export env variable to point at environment against which tests should run: + + export BVT_ENV={env_name} + +You can either use one of environments listed in `config.js`, or add there your own by the analogy of existing ones. + +A list of available environments: + +* STAGE +* STAGE-TPG +* STAGE-TD +* TEST +* FEATURE-BRANCH-APPLE +* APPLIANCE-KANGAROOS + +**Make sure to specify the variable value in upper case!** + +--- + +#### Run Tests Manually + +To run build verification tests: + + make test-bvt + +**[WIP]** To run API tests: + + make test-api + +To configure API test run with specific tests you need: + + + ava -v --concurrency=3 --match='[api.{area-to-test}]*' > results.txt 2>&1 + + +* `{area-to-test}` should be replaced with something you want test, e.g.: +`--match='[api.cart]*'` +You can have multiple `--match` parameters in your run command. + +* `--concurrency=3` is a number of concurrent threads in which test files are executed. +I wouldn't recommend increasing this parameter, yet. + +--- + +#### Reporting + +To generate report, run: + + make report + +To open report, run: + + allure report open + diff --git a/build-tests/config.js b/build-tests/config.js index c67cb9c287..821242a1ff 100644 --- a/build-tests/config.js +++ b/build-tests/config.js @@ -38,11 +38,11 @@ export default { fullApiSequenceLogging: false, }, 'STAGE-TD': { - apiUrl: 'https://td-prod.foxcommerce.com', + apiUrl: 'https://td-stage.foxcommerce.com', storefronts: [ { name: 'TD', - url: 'https://td-prod.foxcommerce.com/', + url: 'https://td-stage.foxcommerce.com/', categories: TD_CATEGORIES, }, ], @@ -51,18 +51,18 @@ export default { testGiftCardFlow: false, fullApiSequenceLogging: false, }, - 'APPLIANCE-AEMXDP': { - apiUrl: 'https://appliance-10-240-0-51.foxcommerce.com', + 'TEST': { + apiUrl: 'https://test.foxcommerce.com', storefronts: [ { name: 'TPG', - url: 'https://appliance-10-240-0-51.foxcommerce.com/perfect-gourmet', + url: 'https://test.foxcommerce.com/perfect-gourmet', categories: TPG_CATEGORIES, aboutPagePath: 'about', }, { name: 'TD', - url: 'https://appliance-10-240-0-51.foxcommerce.com/top-drawer', + url: 'https://test.foxcommerce.com/top-drawer', categories: TD_CATEGORIES, }, ], @@ -71,4 +71,44 @@ export default { testGiftCardFlow: false, fullApiSequenceLogging: false, }, -}[process.env['BVT_ENV'] || 'APPLIANCE-AEMXDP']; + 'FEATURE-BRANCH-APPLE': { + apiUrl: 'https://feature-branch-apple.foxcommerce.com', + storefronts: [ + { + name: 'TPG', + url: 'https://feature-branch-apple.foxcommerce.com/perfect-gourmet', + categories: TPG_CATEGORIES, + aboutPagePath: 'about', + }, + { + name: 'TD', + url: 'https://feature-branch-apple.foxcommerce.com/top-drawer', + categories: TD_CATEGORIES, + }, + ], + stripeKey: 'pk_test_JvTXpI3DrkV6QwdcmZarmlfk', + networkErrorRetries: 4, + testGiftCardFlow: false, + fullApiSequenceLogging: false, + }, + 'APPLIANCE-KANGAROOS': { + apiUrl: 'https://appliance-10-240-0-7.foxcommerce.com', + storefronts: [ + { + name: 'TPG', + url: 'https://appliance-10-240-0-7.foxcommerce.com/perfect-gourmet', + categories: TPG_CATEGORIES, + aboutPagePath: 'about', + }, + { + name: 'TD', + url: 'https://appliance-10-240-0-7.foxcommerce.com/top-drawer', + categories: TD_CATEGORIES, + }, + ], + stripeKey: 'pk_test_JvTXpI3DrkV6QwdcmZarmlfk', + networkErrorRetries: 4, + testGiftCardFlow: false, + fullApiSequenceLogging: false, + }, +}[process.env['BVT_ENV']]; diff --git a/build-tests/helpers/createCreditCard.js b/build-tests/helpers/createCreditCard.js index 86f50c7a38..0c941a200a 100644 --- a/build-tests/helpers/createCreditCard.js +++ b/build-tests/helpers/createCreditCard.js @@ -1,8 +1,9 @@ import $ from '../payloads'; +import * as step from './steps'; export default async (api, customerId) => { const creditCardDetails = $.randomCreditCardDetailsPayload(customerId); - const newTokenResponse = await api.dev.creditCardToken(creditCardDetails); + const newTokenResponse = await step.getCreditCardToken(api, creditCardDetails); const payload = { token: newTokenResponse.token, lastFour: newTokenResponse.lastFour, @@ -13,5 +14,5 @@ export default async (api, customerId) => { billingAddress: creditCardDetails.address, addressIsNew: true, }; - return api.customerCreditCards.add(customerId, payload); + return step.addCustomerCreditCard(api, customerId, payload); }; diff --git a/build-tests/helpers/placeRandomOrder.js b/build-tests/helpers/placeRandomOrder.js index fbf13ce90c..c80689367d 100644 --- a/build-tests/helpers/placeRandomOrder.js +++ b/build-tests/helpers/placeRandomOrder.js @@ -2,26 +2,28 @@ import createCreditCard from './createCreditCard'; import waitFor from './waitFor'; import { AdminApi, CustomerApi } from '../helpers/Api'; import $ from '../payloads'; +import * as step from '../helpers/steps'; -export default async (t) => { - const adminApi = await AdminApi.loggedIn(t); +export default async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); const credentials = $.randomUserCredentials(); - const newCustomer = await adminApi.customers.create(credentials); - const newCard = await createCreditCard(adminApi, newCustomer.id); + const newCustomer = await step.createNewCustomer(api, credentials); + const newCard = await createCreditCard(api, newCustomer.id); const productPayload = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); - const newProduct = await adminApi.products.create('default', productPayload); + const newProduct = await step.createNewProduct(api, 'default', productPayload); const skuCode = newProduct.skus[0].attributes.code.v; - const inventory = await waitFor(500, 10000, () => adminApi.inventories.get(skuCode)); + const inventory = await waitFor(500, 10000, () => step.getInventorySkuCode(api, skuCode)); const stockItemId = inventory.summary.find(item => item.type === 'Sellable').stockItem.id; - await adminApi.inventories.increment(stockItemId, { qty: 1, status: 'onHand', type: 'Sellable' }); - const customerApi = new CustomerApi(t); - await customerApi.auth.login(credentials.email, credentials.password, $.customerOrg); - await customerApi.cart.get(); - await customerApi.cart.addSku(skuCode, 1); - await customerApi.cart.setShippingAddress($.randomCreateAddressPayload()); - const shippingMethod = $.randomArrayElement(await customerApi.cart.getShippingMethods()); - await customerApi.cart.chooseShippingMethod(shippingMethod.id); - await customerApi.cart.addCreditCard(newCard.id); - const fullOrder = await customerApi.cart.checkout(); + await step.incrementInventories(api, stockItemId, { qty: 1, status: 'onHand', type: 'Sellable' }); + const customerApi = new CustomerApi; + await step.login(customerApi, credentials.email, credentials.password, $.customerOrg); + await step.getCurrentCart(customerApi); + await step.addSkuToCart(customerApi, skuCode, 1); + await step.setShippingAddress(customerApi, $.randomCreateAddressPayload()); + const shippingMethod = $.randomArrayElement(await step.getShippingMethods(customerApi)); + await step.chooseShippingMethod(customerApi, shippingMethod.id); + await step.addCreditCard(customerApi, newCard.id); + const fullOrder = await step.checkout(customerApi); return { fullOrder, newCard, newCustomer }; }; diff --git a/build-tests/helpers/steps.js b/build-tests/helpers/steps.js new file mode 100644 index 0000000000..cb2386e095 --- /dev/null +++ b/build-tests/helpers/steps.js @@ -0,0 +1,251 @@ +import $ from '../payloads'; +import superagent from 'superagent'; + +//TODO structure steps, to make them more readable + +export const signup = allure.createStep('Sign Up', (api, email, name, password) => ( + api.auth.signup(email, name, password) +)); + +export const login = allure.createStep('Login', (api, email, password, org) => ( + api.auth.login(email, password, org) +)); + +export const loginAsAdmin = (api) => login(api, $.adminEmail, $.adminPassword, $.adminOrg); + +export const logout = allure.createStep('Logout', (api) => ( + api.auth.logout() +)); + +export const loginAsCustomer = async (api) => { + const { email, name, password } = $.randomUserCredentials(); + const account = await signup(api, email, name, password); + await login(api, email, password, $.customerOrg); + api.account = { id: account.user.id, email, name, password }; + return api; +}; + +export const getAccount = allure.createStep('Get account', (api) => ( + api.account.get() +)); + +export const getStoreAdmins = allure.createStep('List all store admins', (api) => ( + api.storeAdmins.list() +)); + +export const getStoreAdmin = allure.createStep('Get single store admin from the list', (api, storeAdmins) => ( + api.storeAdmins.one(storeAdmins[0].id) +)); + +export const createAdminUser = allure.createStep('Create new store admin user', (api, payload) => ( + api.storeAdmins.create(payload) +)); + +export const updateAdminUser = allure.createStep('Change existing admin user details', (api, adminId, payload) => ( + api.storeAdmins.update(adminId, payload) +)); + +export const createNewCustomer = allure.createStep('Create new customer', (api, credentials) => ( + api.customers.create(credentials) +)); + +export const getCreditCardToken = allure.createStep('Get credit card token', (api, payload) => ( + api.dev.creditCardToken(payload) +)); + +export const createNewPromotion = allure.createStep('Create new promotion', (api, context, payload) => ( + api.promotions.create(context, payload) +)); + +export const createNewCoupon = allure.createStep('Create new coupon', (api, context, payload) => ( + api.coupons.create(context, payload) +)); + +export const getCoupon = allure.createStep('Get a single coupon', (api, context, couponId) => ( + api.coupons.one(context, couponId) +)); + +export const updateCoupon = allure.createStep('Update coupon', (api, context, couponId, payload) => ( + api.coupons.update(context, couponId, payload) +)); + +export const generateCouponCodes = allure.createStep('Generate coupon codes', (api, couponId, payload) => ( + api.couponCodes.generate(couponId, payload) +)); + +export const getCouponCodes = allure.createStep('List coupon codes', (api, couponId) => ( + api.couponCodes.list(couponId) +)); + +export const getNotes = allure.createStep('List test notes', (api, objectType, selectId) => ( + api.notes.list(objectType, selectId) +)); + +export const newNote = allure.createStep('Create new note', (api, objectType, selectId, payload) => ( + api.notes.create(objectType, selectId, payload) +)); + +export const updateNote = allure.createStep('Update note', (api, objectType, selectId, noteId, payload) => ( + api.notes.update(objectType, selectId, noteId, payload) +)); + +export const addCustomerCreditCard = allure.createStep('Add customer credit card', (api, customerId, payload) => ( + api.customerCreditCards.add(customerId, payload) +)); + +export const createNewProduct = allure.createStep('Create new product', (api, context, payload) => ( + api.products.create(context, payload) +)); + +export const getInventorySkuCode = allure.createStep('Get SKU code from inventory', (api, skuCode) => ( + api.inventories.get(skuCode) +)); + +export const incrementInventories = allure.createStep('Increment inventories', (api, itemId, payload) => ( + api.inventories.increment(itemId, payload) +)); + +export const getCurrentCart = allure.createStep('Get current cart', (api) => ( + api.cart.get() +)); + +export const addSkuToCart = allure.createStep('add SKU to cart', (api, skuCode, quantity, attrs) => ( + api.cart.addSku(skuCode, quantity, attrs) +)); + +export const setShippingAddress = allure.createStep('set Shipping address to cart', (api, payload) => ( + api.cart.setShippingAddress(payload) +)); + +export const getShippingMethods = allure.createStep('List shipping methods', (api) => ( + api.cart.getShippingMethods() +)); + +export const getCartsShippingMethods = allure.createStep('List carts shipping methods', (api, cart) => ( + api.carts.getShippingMethods(cart.referenceNumber) +)); + +export const chooseShippingMethod = allure.createStep('Choose shipping method', (api, method) => ( + api.cart.chooseShippingMethod(method.id) +)); + +export const addCreditCard = allure.createStep('Add credit card', (api, cardId) => ( + api.cart.addCreditCard(cardId) +)); + +export const checkout = allure.createStep('Checkout', (api) => ( + api.cart.checkout() +)); + +export const getOrder = allure.createStep('Get a single order', (api, referenceNumber) => ( + api.orders.one(referenceNumber) +)); + +export const updateOrder = allure.createStep('Update order', (api, referenceNumber, payload) => ( + api.orders.update(referenceNumber, payload) +)); + +export const increaseRemorsePeriod = allure.createStep('Increase remorse period', (api, referenceNumber) => ( + api.orders.increaseRemorsePeriod(referenceNumber) +)); + +export const getShipments = allure.createStep('List shipments', (api, referenceNumber) => ( + api.inventories.getShipments(referenceNumber) +)); + +export const createNewGiftCard = allure.createStep('Create new gift card', (api, payload) => ( + api.giftCards.create(payload) +)); + +export const getGiftCard = allure.createStep('Get a single gift card', (api, giftCardCode) => ( + api.giftCards.one(giftCardCode) +)); + +export const updateGiftCard = allure.createStep('Update gift card', (api, giftCardCode, payload) => ( + api.giftCards.update(giftCardCode, payload) +)); + +export const deleteSharedSearch = allure.createStep('Delete shared search', (api, code) => ( + api.sharedSearches.delete(code) +)); + +export const listSharedSearch = allure.createStep('List shared search', (api, scope) => ( + api.sharedSearches.list(scope) +)); + +export const createNewSharedSearch = allure.createStep('Create new shared search', (api, payload) => ( + api.sharedSearches.create(payload) +)); + +export const getSharedSearch = allure.createStep('Get a single shared search', (api, code) => ( + api.sharedSearches.one(code) +)); + +export const getAssociates = allure.createStep('Get shared search associates', (api, code) => ( + api.sharedSearches.getAssociates(code) +)); + +export const addAssociate = allure.createStep('Add shared search associates', (api, code, payload) => ( + api.sharedSearches.addAssociate(code, payload) +)); + +export const removeAssociate = allure.createStep('Remove shared search associates', (api, code, adminId) => ( + api.sharedSearches.removeAssociate(code, adminId) +)); + +export const updateQty = allure.createStep('Update quantity in cart', (api, skuCode, newQty) => ( + api.cart.updateQty(skuCode, newQty) +)); + +export const removeSku = allure.createStep('Remove SKU', (api, skuCode) => ( + api.cart.removeSku(skuCode) +)); + +export const removeCreditCards = allure.createStep('Remove credit cards', (api, skuCode) => ( + api.cart.removeCreditCards(skuCode) +)); + +export const addGiftCard = allure.createStep('Add Gift card', (api, payload) => ( + api.cart.addGiftCard(payload) +)); + +export const removeGiftCard = allure.createStep('Remove Gift card', (api, giftCardCode) => ( + api.cart.removeGiftCard(giftCardCode) +)); + +export const issueStoreCredit = allure.createStep('Issue store credit', (api, customerApi, payload) => ( + api.customers.issueStoreCredit(customerApi.account.id, payload) +)); + +export const addStoreCredit = allure.createStep('Add store credit', (api, availableBalance) => ( + api.cart.addStoreCredit(availableBalance) +)); + +export const removeStoreCredits = allure.createStep('Remove store credit', (api) => ( + api.cart.removeStoreCredits() +)); + +export const addCoupon = allure.createStep('Add coupon', (api, couponCode) => ( + api.cart.addCoupon(couponCode) +)); + +export const removeCoupon = allure.createStep('Remove coupon', (api, couponCode) => ( + api.cart.removeCoupon() +)); + +export const getCart = allure.createStep('Get a single cart', (api, referenceNumber) => ( + api.carts.one(referenceNumber) +)); + +export const addLineItemQuantities = allure.createStep('Add line item quantities', (api, referenceNumber, payload) => ( + api.carts.addLineItemQuantities(referenceNumber, payload) +)); + +export const getPage = allure.createStep('Get page', (url) => ( + superagent.get(url) +)); + +export const userGetPage = allure.createStep('Authorized get page', (api, url) => ( + api.agent.get(url) +)); + diff --git a/build-tests/mocha.opts b/build-tests/mocha.opts new file mode 100644 index 0000000000..8bea697ae3 --- /dev/null +++ b/build-tests/mocha.opts @@ -0,0 +1,3 @@ +--timeout 60000 +--reporter mocha-multi +--require babel-register \ No newline at end of file diff --git a/build-tests/package.json b/build-tests/package.json index a9ee3e1a76..0813a7128a 100644 --- a/build-tests/package.json +++ b/build-tests/package.json @@ -34,11 +34,14 @@ }, "devDependencies": { "babel-eslint": "^7.1.1", + "chai": "^4.0.2", "eslint": "^3.14.1", "eslint-config-airbnb": "^14.0.0", "eslint-plugin-import": "^2.2.0", "eslint-plugin-jsx-a11y": "^3.0.2", - "eslint-plugin-react": "^6.9.0" + "eslint-plugin-react": "^6.9.0", + "mocha": "^3.4.2", + "mocha-allure-reporter": "^1.3.2" }, "ava": { "require": [ diff --git a/build-tests/test/auth.spec.js b/build-tests/test/auth.spec.js new file mode 100644 index 0000000000..19cc3c9e86 --- /dev/null +++ b/build-tests/test/auth.spec.js @@ -0,0 +1,81 @@ +import { CustomerApi, AdminApi } from '../helpers/Api'; +import isString from '../helpers/isString'; +import isNumber from '../helpers/isNumber'; +import isDate from '../helpers/isDate'; +import $ from '../payloads'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +describe('[bvt] Auth', function() { + + this.timeout(30000); + + it('[bvt] Can sign up', async () => { + const api = new CustomerApi; + const { email, name, password } = $.randomUserCredentials(); + const signupResponse = await step.signup(api, email, name, password); + + expect(isString(signupResponse.jwt)).to.be.true; + expect(signupResponse.jwt.length > 0).to.be.true; + expect(isNumber(signupResponse.user.id)).to.be.true; + expect(isDate(signupResponse.user.createdAt)).to.be.true; + expect(signupResponse.user.email).to.equal(email); + expect(signupResponse.user.name).to.equal(name); + expect(signupResponse.user.disabled).to.be.false; + expect(signupResponse.user.isGuest).to.be.false; + expect(signupResponse.user.isBlacklisted).to.be.false; + expect(signupResponse.user.totalSales).to.equal(0); + expect(signupResponse.user.storeCreditTotals.availableBalance).to.equal(0); + expect(signupResponse.user.storeCreditTotals.currentBalance).to.equal(0); + }); + + it('[bvt] Can sign in as customer', async () => { + const api = new CustomerApi; + const { email, name, password } = $.randomUserCredentials(); + await step.signup(api, email, name, password); + const loginResponse = await step.login(api, email, password, $.customerOrg); + expect(loginResponse.jwt, 'Login response should have a "jwt" field.').to.exist; + expect(loginResponse.user.name, 'Username in login response doesn\'t match real username.').to.equal(name); + expect(loginResponse.user.email, 'Email in login response doesn\'t match real user email.').to.equal(email); + }); + + it('[bvt] Can sign in as admin', async () => { + const api = new AdminApi; + const loginResponse = await step.login(api, $.adminEmail, $.adminPassword, $.adminOrg); + expect(loginResponse.jwt, 'Login response should have a "jwt" field.').to.exist; + expect(loginResponse.user && loginResponse.user.name, 'Login response should have an "user.name" field.').to.exist; + expect(loginResponse.user && loginResponse.user.email, 'Login response should have an "user.email" field.').to.exist; + }); + + + it('[bvt] Can\'t sign in as admin with a customer org', async () => { + const api = new AdminApi; + try { + await step.login(api, $.adminEmail, $.adminPassword, $.customerOrg); + expect('Signing in as admin with a customer org should have failed, but it succeeded.').to.be.false; + } catch (error) { + if (error && error.response) { + expect(error.response.status).to.equal(400); + expect(error.response.clientError).to.be.true; + expect(error.response.serverError).to.be.false; + } else { + throw error; + } + } + }); + + it('[bvt] Can sign out', async () => { + const api = new CustomerApi; + await step.login(api, $.adminEmail, $.adminPassword, $.adminOrg); + await step.logout(api) + }); + + it('[bvt] Can view customer account details', async () => { + const api = new CustomerApi; + const { email, name, password } = $.randomUserCredentials(); + const signupResponse = await step.signup(api, email, name, password); + const foundAccount = await step.getAccount(api); + expect(foundAccount).to.deep.equal(signupResponse.user); + }); + +}); diff --git a/build-tests/test/cart.spec.js b/build-tests/test/cart.spec.js new file mode 100644 index 0000000000..14407ab030 --- /dev/null +++ b/build-tests/test/cart.spec.js @@ -0,0 +1,338 @@ +import createCreditCard from '../helpers/createCreditCard'; +import placeRandomOrder from '../helpers/placeRandomOrder'; +import { AdminApi, CustomerApi } from '../helpers/Api'; +import isArray from '../helpers/isArray'; +import isString from '../helpers/isString'; +import isNumber from '../helpers/isNumber'; +import isDate from '../helpers/isDate'; +import $ from '../payloads'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +describe('Cart', function() { + + this.timeout(30000); + + it('[bvt] Can add line item', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const productPayload = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); + const newProduct = await step.createNewProduct(api, 'default', productPayload); + const customerApi = new CustomerApi; + const { email, name, password } = $.randomUserCredentials(); + await step.signup(customerApi, email, name, password); + await step.login(customerApi, email, password, $.customerOrg); + await step.getCurrentCart(customerApi); + const skuCode = newProduct.skus[0].attributes.code.v; + const quantity = $.randomNumber(1, 10); + const fullOrder = await step.addSkuToCart(customerApi, skuCode, quantity).then(r => r.result); + expect(fullOrder.lineItems).to.exist; + expect(isArray(fullOrder.lineItems.skus)).to.be.true; + expect(fullOrder.lineItems.skus.length).to.equal(1); + expect(fullOrder.lineItems.skus[0].sku).to.equal(skuCode); + expect(fullOrder.lineItems.skus[0].quantity).to.equal(quantity); + // Skipped since of wrong response from backend in line 19 (total price wasnt updated for skus) + // const foundOrder = await getCurrentCart(customerApi); + // expect(foundOrder).to.deep.equal(fullOrder); + }); + + it('[bvt] Can update line item', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const productPayload = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); + const newProduct = await step.createNewProduct(api, 'default', productPayload); + const customerApi = new CustomerApi; + const { email, name, password } = $.randomUserCredentials(); + await step.signup(customerApi, email, name, password); + await step.login(customerApi, email, password, $.customerOrg); + await step.getCurrentCart(customerApi); + const skuCode = newProduct.skus[0].attributes.code.v; + await step.addSkuToCart(customerApi, skuCode, 1); + const newQuantity = $.randomNumber(2, 10); + const fullOrder = await step.updateQty(customerApi, skuCode, newQuantity).then(r => r.result); + expect(fullOrder.lineItems).to.exist; + expect(isArray(fullOrder.lineItems.skus)).to.be.true; + expect(fullOrder.lineItems.skus.length).to.equal(1); + expect(fullOrder.lineItems.skus[0].sku).to.equal(skuCode); + expect(fullOrder.lineItems.skus[0].quantity).to.equal(newQuantity); + // Skipped since of wrong response from backend in line 39 (total price wasnt updated for skus) + // const foundOrder = await customerApi.cart.get(); + // t.deepEqual(foundOrder, fullOrder); + }); + + it('[bvt] Can remove line item', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const productPayload = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); + const newProduct = await step.createNewProduct(api, 'default', productPayload); + const customerApi = new CustomerApi; + const { email, name, password } = $.randomUserCredentials(); + await step.signup(customerApi, email, name, password); + await step.login(customerApi, email, password, $.customerOrg); + await step.getCurrentCart(customerApi); + const skuCode = newProduct.skus[0].attributes.code.v; + await step.addSkuToCart(customerApi, skuCode, 1); + const fullOrder = await customerApi.cart.removeSku(skuCode).then(r => r.result); + expect(fullOrder.lineItems).to.exist; + expect(isArray(fullOrder.lineItems.skus)).to.be.true; + expect(fullOrder.lineItems.skus.length).to.equal(0); + const foundOrder = await step.getCurrentCart(customerApi); + expect(foundOrder).to.deep.equal(fullOrder); + }); + + it('[bvt] Can set shipping address', async () => { + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + await step.getCurrentCart(customerApi); + const payload = $.randomCreateAddressPayload(); + const fullOrder = await step.setShippingAddress(customerApi, payload).then(r => r.result); + const shippingAddress = fullOrder.shippingAddress; + expect(shippingAddress.name).to.equal(payload.name); + expect(shippingAddress.region.id).to.equal(payload.regionId); + expect(shippingAddress.address1).to.equal(payload.address1); + expect(shippingAddress.address2).to.equal(payload.address2); + expect(shippingAddress.city).to.equal(payload.city); + expect(shippingAddress.zip).to.equal(payload.zip); + + // Does not work, since there is no isDefault prop in response + // expect(shippingAddress.isDefault).to.equal(payload.isDefault); + + expect(shippingAddress.phoneNumber).to.equal(payload.phoneNumber); + const foundOrder = await step.getCurrentCart(customerApi); + expect(foundOrder).to.deep.equal(fullOrder); + }); + + it('[bvt] Can list available shipping methods', async () => { + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + await step.getCurrentCart(customerApi); + await step.setShippingAddress(customerApi, $.randomCreateAddressPayload()); + const shippingMethods = await step.getShippingMethods(customerApi); + expect(isArray(shippingMethods)).to.be.true; + for (const shippingMethod of shippingMethods) { + expect(isNumber(shippingMethod.id)).to.be.true; + expect(isNumber(shippingMethod.price)).to.be.true; + expect(isString(shippingMethod.name)).to.be.true; + expect(isString(shippingMethod.code)).to.be.true; + } + }); + + it('[bvt] Can choose shipping method', async () => { + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + await step.getCurrentCart(customerApi); + await step.setShippingAddress(customerApi, $.randomCreateAddressPayload()); + const shippingMethods = await step.getShippingMethods(customerApi); + const shippingMethod = $.randomArrayElement(shippingMethods); + const fullOrder = await step.chooseShippingMethod(customerApi, shippingMethod).then(r => r.result); + expect(fullOrder.shippingMethod).to.deep.equal(shippingMethod); + const foundOrder = await step.getCurrentCart(customerApi); + expect(foundOrder).to.deep.equal(fullOrder); + }); + + // works only on stage-tpg ¯\_(ツ)_/¯ + it('[bvt] Can apply credit card', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const credentials = $.randomUserCredentials(); + const newCustomer = await step.createNewCustomer(api, credentials); + const newCard = await createCreditCard(api, newCustomer.id); + const customerApi = new CustomerApi; + await step.login(customerApi, credentials.email, credentials.password, $.customerOrg); + await step.getCurrentCart(customerApi); + const fullOrder = await step.addCreditCard(customerApi, newCard.id).then(r => r.result); + expect(isArray(fullOrder.paymentMethods)).to.be.true; + expect(fullOrder.paymentMethods.length).to.equal(1); + const orderCreditCard = fullOrder.paymentMethods[0]; + expect(orderCreditCard.type).to.equal('creditCard'); + expect(orderCreditCard.id).to.equal(newCard.id); + expect(orderCreditCard.customerId).to.equal(newCard.customerId); + expect(orderCreditCard.holderName).to.equal(newCard.holderName); + expect(orderCreditCard.lastFour).to.equal(newCard.lastFour); + expect(orderCreditCard.expMonth).to.equal(newCard.expMonth); + expect(orderCreditCard.expYear).to.equal(newCard.expYear); + expect(orderCreditCard.brand).to.equal(newCard.brand); + expect(orderCreditCard.address).to.deep.equal(newCard.address); + const foundOrder = await step.getCurrentCart(customerApi); + expect(foundOrder).to.deep.equal(fullOrder); + }); +// + //works only on stage-tpg ¯\_(ツ)_/¯ + it('[bvt] Can remove credit card', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const credentials = $.randomUserCredentials(); + const newCustomer = await step.createNewCustomer(api, credentials); + const newCard = await createCreditCard(api, newCustomer.id); + const customerApi = new CustomerApi; + await step.login(customerApi, credentials.email, credentials.password, $.customerOrg); + await step.getCurrentCart(customerApi); + const fullOrderAfterAddingCC = await step.addCreditCard(customerApi, newCard.id).then(r => r.result); + expect(isArray(fullOrderAfterAddingCC.paymentMethods)).to.be.true; + expect(fullOrderAfterAddingCC.paymentMethods.length).to.equal(1); + const fullOrderAfterRemovingCC = await step.removeCreditCards(customerApi).then(r => r.result); + expect(isArray(fullOrderAfterRemovingCC.paymentMethods)).to.be.true; + expect(fullOrderAfterRemovingCC.paymentMethods.length).to.equal(0); + const foundOrder = await step.getCurrentCart(customerApi); + expect(foundOrder).to.deep.equal(fullOrderAfterRemovingCC); + }); + + it('[bvt] Can apply gift card', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const giftCardPayload = $.randomGiftCardPayload(); + const newGiftCard = await step.createNewGiftCard(api, giftCardPayload); + const customerApi = new CustomerApi; + const credentials = $.randomUserCredentials(); + await step.signup(customerApi, credentials.email, credentials.name, credentials.password); + await step.login(customerApi, credentials.email, credentials.password, $.customerOrg); + await step.getCurrentCart(customerApi); + const payload = { code: newGiftCard.code, amount: newGiftCard.availableBalance }; + const fullOrder = await step.addGiftCard(customerApi, payload).then(r => r.result); + expect(isArray(fullOrder.paymentMethods)).to.be.true; + expect(fullOrder.paymentMethods.length).to.equal(1); + const orderGiftCard = fullOrder.paymentMethods[0]; + expect(orderGiftCard.code).to.equal(payload.code); + expect(orderGiftCard.amount).to.equal(payload.amount); + expect(orderGiftCard.type).to.equal('giftCard'); + expect(orderGiftCard.currentBalance).to.equal(newGiftCard.currentBalance); + expect(orderGiftCard.availableBalance).to.equal(newGiftCard.availableBalance); + expect(orderGiftCard.createdAt).to.equal(newGiftCard.createdAt); + const foundOrder = await step.getCurrentCart(customerApi); + expect(foundOrder).to.deep.equal(fullOrder); + }); + + it('[bvt] Can remove gift card', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const giftCardPayload = $.randomGiftCardPayload(); + const newGiftCard = await step.createNewGiftCard(api, giftCardPayload); + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + await step.getCurrentCart(customerApi); + const payload = { code: newGiftCard.code, amount: newGiftCard.availableBalance }; + const fullOrderAfterAddingGC = await step.addGiftCard(customerApi, payload).then(r => r.result); + expect(isArray(fullOrderAfterAddingGC.paymentMethods)).to.be.true; + expect(fullOrderAfterAddingGC.paymentMethods.length).to.equal(1); + const fullOrderAfterRemovingGC = await step.removeGiftCard(customerApi, payload.code).then(r => r.result); + expect(isArray(fullOrderAfterRemovingGC.paymentMethods)).to.be.true; + expect(fullOrderAfterRemovingGC.paymentMethods.length).to.equal(0); + const foundOrder = await step.getCurrentCart(customerApi); + expect(foundOrder).to.deep.equal(fullOrderAfterRemovingGC); + }); + + it('[bvt] Can apply store credit', async () => { + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + const api = new AdminApi; + await step.loginAsAdmin(api); + const storeCreditPayload = $.randomStoreCreditPayload(); + const newStoreCredit = await step.issueStoreCredit(api, customerApi, storeCreditPayload); + await step.getCurrentCart(customerApi); + const fullOrder = await step.addStoreCredit(customerApi, newStoreCredit.availableBalance).then(r => r.result); + expect(isArray(fullOrder.paymentMethods)).to.be.true; + expect(fullOrder.paymentMethods.length, 1).to.equal(1); + const orderStoreCredit = fullOrder.paymentMethods[0]; + expect(orderStoreCredit.type).to.equal('storeCredit'); + expect(orderStoreCredit.id).to.equal(newStoreCredit.id); + expect(orderStoreCredit.amount).to.equal(newStoreCredit.availableBalance); + expect(orderStoreCredit.availableBalance).to.equal(newStoreCredit.availableBalance); + expect(orderStoreCredit.currentBalance).to.equal(newStoreCredit.currentBalance); + expect(orderStoreCredit.createdAt).to.equal(newStoreCredit.createdAt); + const foundOrder = await step.getCurrentCart(customerApi); + expect(foundOrder).to.deep.equal(fullOrder); + }); + + it('[bvt] Can remove store credit', async () => { + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + const api = new AdminApi; + await step.loginAsAdmin(api); + const storeCreditPayload = $.randomStoreCreditPayload(); + const newStoreCredit = await step.issueStoreCredit(api, customerApi, storeCreditPayload); + await step.getCurrentCart(customerApi); + const fullOrderAfterAddingSC = + await step.addStoreCredit(customerApi, newStoreCredit.availableBalance).then(r => r.result); + expect(isArray(fullOrderAfterAddingSC.paymentMethods)).to.be.true; + expect(fullOrderAfterAddingSC.paymentMethods.length).to.equal(1); + const fullOrderAfterRemovingSC = await step.removeStoreCredits(customerApi).then(r => r.result); + expect(isArray(fullOrderAfterRemovingSC.paymentMethods)).to.be.true; + expect(fullOrderAfterRemovingSC.paymentMethods.length).to.equal(0); + const foundOrder = await step.getCurrentCart(customerApi); + expect(foundOrder).to.deep.equal(fullOrderAfterRemovingSC); + }); + + it('[bvt] Can apply coupon', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const context = 'default'; + const newPromotion = await step.createNewPromotion(api, context, $.randomCreatePromotionPayload()); + const newCoupon = await step.createNewCoupon(api, context, $.randomCouponPayload(newPromotion.id)); + const couponCodes = await step.generateCouponCodes(api, newCoupon.id, $.randomGenerateCouponCodesPayload()); + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + await step.getCurrentCart(customerApi); + const couponCode = $.randomArrayElement(couponCodes); + + // coupon cannot be added to cart without scu + const productPayload = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); + const newProduct = await step.createNewProduct(api, 'default', productPayload); + const skuCode = newProduct.skus[0].attributes.code.v; + await step.addSkuToCart(customerApi, skuCode, 1).then(r => r.result); + + const fullOrder = await step.addCoupon(customerApi, couponCode).then(r => r.result); + const coupon = fullOrder.coupon; + expect(coupon.code).to.equal(couponCode); + expect(coupon.coupon).to.deep.equal(newCoupon); + const foundOrder = await step.getCurrentCart(customerApi); + expect(foundOrder).to.deep.equal(fullOrder) + }); + + it('[bvt] Can remove coupon', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const context = 'default'; + const newPromotion = await step.createNewPromotion(api, context, $.randomCreatePromotionPayload()); + const newCoupon = await step.createNewCoupon(api, context, $.randomCouponPayload(newPromotion.id)); + const couponCodes = await step.generateCouponCodes(api, newCoupon.id, $.randomGenerateCouponCodesPayload()); + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + await step.getCurrentCart(customerApi); + const couponCode = $.randomArrayElement(couponCodes); + + // coupon cannot be added to cart without scu + const productPayload = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); + const newProduct = await step.createNewProduct(api, 'default', productPayload); + const skuCode = newProduct.skus[0].attributes.code.v; + await step.addSkuToCart(customerApi, skuCode, 1).then(r => r.result); + + const fullOrderAfterAddingCoupon = await step.addCoupon(customerApi, couponCode).then(r => r.result); + expect(fullOrderAfterAddingCoupon.coupon).to.exist; + const fullOrderAfterRemovingCoupon = await step.removeCoupon(customerApi).then(r => r.result); + expect(fullOrderAfterRemovingCoupon.coupon).to.not.exist; + const foundOrder = await step.getCurrentCart(customerApi); + + // doesnt work since autopromotion isnt shown for response from fullOrderAfterRemovingCoupon + // t.deepEqual(foundOrder, fullOrderAfterRemovingCoupon); + }); + + //works only on stage-tpg ¯\_(ツ)_/¯ + it('[bvt] Can checkout a cart', async () => { + const { fullOrder, newCard, newCustomer } = await placeRandomOrder(); + expect(fullOrder.paymentState).to.equal('auth'); + expect(fullOrder.orderState).to.equal('remorseHold'); + expect(fullOrder.shippingState).to.equal('remorseHold'); + expect(isDate(fullOrder.placedAt)).to.be.true; + expect(isDate(fullOrder.remorsePeriodEnd)).to.be.true; + expect(fullOrder.billingAddress).to.deep.equal(newCard.address); + expect(fullOrder.billingCreditCardInfo.type).to.equal('creditCard'); + expect(fullOrder.billingCreditCardInfo.id).to.equal(newCard.id); + expect(fullOrder.billingCreditCardInfo.customerId).to.equal(newCard.customerId); + expect(fullOrder.billingCreditCardInfo.holderName).to.equal(newCard.holderName); + expect(fullOrder.billingCreditCardInfo.lastFour).to.equal(newCard.lastFour); + expect(fullOrder.billingCreditCardInfo.expMonth).to.equal(newCard.expMonth); + expect(fullOrder.billingCreditCardInfo.expYear).to.equal(newCard.expYear); + expect(fullOrder.billingCreditCardInfo.brand).to.equal(newCard.brand); + expect(fullOrder.customer).to.deep.equal(newCustomer); + }); +}); diff --git a/build-tests/test/carts.spec.js b/build-tests/test/carts.spec.js new file mode 100644 index 0000000000..ecab9f1baa --- /dev/null +++ b/build-tests/test/carts.spec.js @@ -0,0 +1,160 @@ +import testNotes from './test-notes'; +import testWatchers from './test-watchers'; +import createCreditCard from '../helpers/createCreditCard'; +import placeRandomOrder from '../helpers/placeRandomOrder'; +import { AdminApi, CustomerApi } from '../helpers/Api'; +import isArray from '../helpers/isArray'; +import isString from '../helpers/isString'; +import isNumber from '../helpers/isNumber'; +import $ from '../payloads'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +describe('Carts', function() { + + this.timeout(30000); + + it('[bvt] Can view cart details', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const credentials = $.randomUserCredentials(); + const newCustomer = await step.createNewCustomer(api, credentials); + const newCard = await createCreditCard(api, newCustomer.id); + const newGiftCard = await step.createNewGiftCard(api, $.randomGiftCardPayload()); + const newPromotion = await step.createNewPromotion(api, 'default', $.randomCreatePromotionPayload()); + const context = 'default'; + const newCoupon = await step.createNewCoupon(api, context, $.randomCouponPayload(newPromotion.id)); + const couponCodes = await step.generateCouponCodes(api, newCoupon.id, $.randomGenerateCouponCodesPayload()); + const couponCode = $.randomArrayElement(couponCodes); + const productPayload = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); + const newProduct = await step.createNewProduct(api, context, productPayload); + const skuCode = newProduct.skus[0].attributes.code.v; + const customerApi = new CustomerApi; + await step.login(customerApi, credentials.email, credentials.password, $.customerOrg); + await step.getCurrentCart(customerApi); + const quantity = $.randomNumber(1, 10); + await step.addSkuToCart(customerApi, skuCode, quantity); + await step.setShippingAddress(customerApi, $.randomCreateAddressPayload()); + const shippingMethod = $.randomArrayElement(await step.getShippingMethods(customerApi)); + await step.chooseShippingMethod(customerApi, shippingMethod.id); + await step.addCreditCard(customerApi, newCard.id); + const gcPayload = { code: newGiftCard.code, amount: newGiftCard.availableBalance }; + await step.addGiftCard(customerApi, gcPayload); + const cart = await step.addCoupon(customerApi, couponCode).then(r => r.result); + const foundCart = await step.getCart(api, cart.referenceNumber).then(r => r.result); + expect(foundCart).to.deep.equal(cart); + }); + + it('[bvt] Can list available shipping methods', async () => { + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + const cart = await step.getCurrentCart(customerApi); + await step.setShippingAddress(customerApi, $.randomCreateAddressPayload()); + const shippingMethodsFromCustomerApi = await step.getShippingMethods(customerApi); + const api = new AdminApi; + await step.loginAsAdmin(api); + const shippingMethodsFromAdminApi = await step.getCartsShippingMethods(api, cart); + expect(isArray(shippingMethodsFromAdminApi)).to.be.true; + for (const shippingMethod of shippingMethodsFromAdminApi) { + expect(isNumber(shippingMethod.id)).to.be.true; + expect(isNumber(shippingMethod.price)).to.be.true; + expect(isString(shippingMethod.name)).to.be.true; + expect(isString(shippingMethod.code)).to.be.true; + } + expect(shippingMethodsFromAdminApi).to.deep.equal(shippingMethodsFromCustomerApi); + }); + + it('[bvt] Can update line items', async () => { + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + const { referenceNumber } = await step.getCurrentCart(customerApi); + const api = new AdminApi; + await step.loginAsAdmin(api); + const productPayload = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); + const newProduct = await step.createNewProduct(api, 'default', productPayload); + const skuCode = newProduct.skus[0].attributes.code.v; + const payload = $.randomLineItemsPayload([skuCode]); + const updatedCart = await step.addLineItemQuantities(api, referenceNumber, payload).then(r => r.result); + expect(updatedCart.lineItems).to.exist; + expect(isArray(updatedCart.lineItems.skus)).to.be.true; + expect(updatedCart.lineItems.skus.length).to.equal(1); + expect(updatedCart.lineItems.skus[0].sku).to.equal(skuCode); + expect(updatedCart.lineItems.skus[0].quantity).to.equal(payload[0].quantity); + + // total price field isn't updated after executing the following line below + // >>> await adminApi.carts.addLineItemQuantities(referenceNumber, payload).then(r => r.result); + // + // const cart = await customerApi.cart.get(); + // t.deepEqual(cart, updatedCart); + }); + + it('[bvt] Updating one line item doesn\'t affect others', async () => { + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + const { referenceNumber } = await step.getCurrentCart(customerApi); + const api = new AdminApi; + await step.loginAsAdmin(api); + const productPayload1 = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); + const newProduct1 = await step.createNewProduct(api, 'default', productPayload1); + const skuCode1 = newProduct1.skus[0].attributes.code.v; + const productPayload2 = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); + const newProduct2 = await step.createNewProduct(api, 'default', productPayload2); + const skuCode2 = newProduct2.skus[0].attributes.code.v; + const placeLineItemsPayload = $.randomLineItemsPayload([skuCode1, skuCode2]); + const [sku1Quantity, sku2Quantity] = placeLineItemsPayload.map(item => item.quantity); + await step.addLineItemQuantities(api, referenceNumber, placeLineItemsPayload); + const updateSku1Payload = { sku: skuCode1, quantity: $.randomNumber(1, 10) }; + const updatedCart = await step + .addLineItemQuantities(api, referenceNumber, [updateSku1Payload]) + .then(r => r.result); + const newSku1Quantity = updatedCart.lineItems.skus.find(item => item.sku === skuCode1).quantity; + const newSku2Quantity = updatedCart.lineItems.skus.find(item => item.sku === skuCode2).quantity; + expect(newSku1Quantity).to.equal(sku1Quantity + updateSku1Payload.quantity); + expect(newSku2Quantity).to.equal(sku2Quantity); + + // total price field isn't updated after executing the following lines below + // >>> await adminApi.carts.addLineItemQuantities(referenceNumber, placeLineItemsPayload); + // >>> await adminApi.carts.addLineItemQuantities(referenceNumber, [updateSku1Payload]).then(r => r.result); + // + // const cart = await customerApi.cart.get(); + // t.deepEqual(cart, updatedCart); + }); + TODO: BROKEN + it('[bvt] Can\'t access the cart once order for it has been placed', async () => { + const { fullOrder } = await placeRandomOrder(); + try { + const api = new AdminApi; + await step.loginAsAdmin(api); + await step.getCart(api, fullOrder.referenceNumber); + expect('Accessing cart after placing order should have failed, but it succeeded.').to.fail; + } catch (error) { + if (error && error.response) { + expect(error.response.status).to.equal(400); + expect(error.response.clientError).to.exist; + expect(error.response.serverError).to.not.exist; + } else { + throw error; + } + } + }); + + testWatchers({ + objectApi: api => api.carts, + createObject: async () => { + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + return await step.getCurrentCart(customerApi); + }, + selectId: cart => cart.referenceNumber, + }); + + testNotes({ + objectType: 'order', + createObject: async (api) => { + const customerApi = await CustomerApi.loggedIn(api.testContext); + return await step.getCurrentCart(customerApi); + }, + selectId: cart => cart.referenceNumber, + }); +}); + diff --git a/build-tests/test/coupon.spec.js b/build-tests/test/coupon.spec.js new file mode 100644 index 0000000000..ce28701447 --- /dev/null +++ b/build-tests/test/coupon.spec.js @@ -0,0 +1,101 @@ +import testNotes from './test-notes'; +import { AdminApi } from '../helpers/Api'; +import isNumber from '../helpers/isNumber'; +import isArray from '../helpers/isArray'; +import isDate from '../helpers/isDate'; +import $ from '../payloads'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +describe('[bvt] Coupon', function() { + this.timeout(30000); + + it('[bvt] Can create a coupon', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newPromotion = await step.createNewPromotion(api, 'default', $.randomCreatePromotionPayload()); + const payload = $.randomCouponPayload(newPromotion.id) + const newCoupon = await step.createNewCoupon(api, 'default', payload); + + // activeFrom date cannot be set for coupon due to intentional decision + payload.attributes.activeFrom.v = newCoupon.attributes.activeFrom.v; + + expect(isNumber(newCoupon.id)).to.be.true; + expect(newCoupon.promotion).to.equal(newPromotion.id); + expect(newCoupon.context.name).to.equal('default'); + expect(newCoupon.attributes).to.deep.equal(payload.attributes); + }); + + it('[bvt] Can view coupon details', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newPromotion = await step.createNewPromotion(api, 'default', $.randomCreatePromotionPayload()); + const newCoupon = await step.createNewCoupon(api, 'default', $.randomCouponPayload(newPromotion.id)); + const foundCoupon = await step.getCoupon(api, 'default', newCoupon.id); + expect(foundCoupon).to.deep.equal(newCoupon); + }); + + it('[bvt] Can update coupon details', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newPromotion = await step.createNewPromotion(api, 'default', $.randomCreatePromotionPayload()); + const newCoupon = await step.createNewCoupon(api, 'default', $.randomCouponPayload(newPromotion.id)); + const payload = $.randomCouponPayload(newPromotion.id); + const updatedCoupon = await step.updateCoupon(api, 'default', newCoupon.id, payload); + + // activeFrom date cannot be set for coupon due to intentional decision + payload.attributes.activeFrom.v = newCoupon.attributes.activeFrom.v; + + expect(updatedCoupon.id).to.equal(newCoupon.id); + expect(updatedCoupon.promotion).to.equal(newPromotion.id); + expect(updatedCoupon.context.name).to.equal('default'); + expect(updatedCoupon.attributes).to.deep.equal(payload.attributes); + }); + + it('[bvt] Can bulk generate the codes', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newPromotion = await step.createNewPromotion(api, 'default', $.randomCreatePromotionPayload()); + const newCoupon = await step.createNewCoupon(api, 'default', $.randomCouponPayload(newPromotion.id)); + const payload = $.randomGenerateCouponCodesPayload(); + const couponCodes = await step.generateCouponCodes(api, newCoupon.id, payload); + expect(isArray(couponCodes)).to.be.true; + expect(couponCodes.length).to.equal(payload.quantity); + for (const code of couponCodes) { + expect(code.indexOf(payload.prefix)).to.equal(0); + expect(code.length).to.equal(payload.length); + } + }); + + it('[bvt] Can view the list of coupon codes', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newPromotion = await step.createNewPromotion(api, 'default', $.randomCreatePromotionPayload()); + const newCoupon = await step.createNewCoupon(api, 'default', $.randomCouponPayload(newPromotion.id)); + const initialCouponCodes = await step.getCouponCodes(api, newCoupon.id); + + expect(isArray(initialCouponCodes)).to.be.true; + expect(initialCouponCodes.length).to.equal(0); + + const payload = $.randomGenerateCouponCodesPayload(); + await step.generateCouponCodes(api, newCoupon.id, payload); + const couponCodesAfterGeneration = await step.getCouponCodes(api, newCoupon.id); + + expect(isArray(couponCodesAfterGeneration)).to.be.true; + expect(couponCodesAfterGeneration.length).to.equal(payload.quantity); + for (const { code, createdAt } of couponCodesAfterGeneration) { + expect(code.indexOf(payload.prefix)).to.equal(0); + expect(code.length).to.equal(payload.length); + expect(isDate(createdAt)).to.be.true; + } + }); + + testNotes({ + objectType: 'coupon', + createObject: async (api) => { + const newPromotion = await step.createNewPromotion(api, 'default', $.randomCreatePromotionPayload()); + return step.createNewCoupon(api, 'default', $.randomCouponPayload(newPromotion.id)); + }, + }); +}); + diff --git a/build-tests/test/dev.spec.js b/build-tests/test/dev.spec.js new file mode 100644 index 0000000000..e6f6077826 --- /dev/null +++ b/build-tests/test/dev.spec.js @@ -0,0 +1,25 @@ +import { AdminApi } from '../helpers/Api'; +import $ from '../payloads'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +describe('[bvt] Credit Card Token', function() { + + this.timeout(30000); + + it('[bvt] Can issue credit card token', async() => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const credentials = $.randomUserCredentials(); + const newCustomer = await step.createNewCustomer(api, credentials); + const cardDetails = $.randomCreditCardDetailsPayload(newCustomer.id); + const response = await step.getCreditCardToken(api, cardDetails); + + expect(response.token.constructor.name).to.exist; + expect(response.brand.constructor.name).to.exist; + expect(response.lastFour.constructor.name).to.exist; + expect(response.token.length).to.equal(28); + expect(response.lastFour.length).to.equal(4); + }); + +}); diff --git a/build-tests/test/gift-card.spec.js b/build-tests/test/gift-card.spec.js new file mode 100644 index 0000000000..f94ae5acc0 --- /dev/null +++ b/build-tests/test/gift-card.spec.js @@ -0,0 +1,132 @@ +import testNotes from './test-notes'; +import { AdminApi, CustomerApi } from '../helpers/Api'; +import createCreditCard from '../helpers/createCreditCard'; +import waitFor from '../helpers/waitFor'; +import isNumber from '../helpers/isNumber'; +import isString from '../helpers/isString'; +import isDate from '../helpers/isDate'; +import $ from '../payloads'; +import config from '../config'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +describe('Gift Card', function() { + + this.timeout(30000); + + it('[bvt] Can create a gift card', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const payload = $.randomGiftCardPayload(); + const newGiftCard = await step.createNewGiftCard(api, payload); + expect(isNumber(newGiftCard.id)).to.be.true; + expect(isDate(newGiftCard.createdAt)).to.be.true; + expect(isString(newGiftCard.code)).to.be.true; + expect(newGiftCard.code.length).to.equal(16); + expect(isNumber(newGiftCard.originId)).to.be.true; + expect(newGiftCard.originType).to.equal('csrAppeasement'); + expect(newGiftCard.state).to.equal('active'); + expect(newGiftCard.currency).to.equal('USD'); + expect(newGiftCard.originalBalance).to.equal(payload.balance); + expect(newGiftCard.availableBalance).to.equal(payload.balance); + expect(newGiftCard.currentBalance).to.equal(payload.balance); + expect(newGiftCard.storeAdmin.email).to.equal($.adminEmail); + expect(newGiftCard.storeAdmin.name).to.equal($.adminName); + }); + + it('[bvt] Can view gift card details', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const payload = $.randomGiftCardPayload(); + const newGiftCard = await step.createNewGiftCard(api, payload); + const foundGiftCard = await step.getGiftCard(api, newGiftCard.code); + expect(foundGiftCard).to.deep.equal(newGiftCard); + }); + + it('[bvt] Can put a gift card "On Hold"', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newGiftCard = await step.createNewGiftCard(api, $.randomGiftCardPayload()); + const updatedGiftCard = await step.updateGiftCard(api, newGiftCard.code, { state: 'onHold' }); + expect(updatedGiftCard.state).to.equal('onHold'); + expect(updatedGiftCard.id).to.equal(newGiftCard.id); + expect(updatedGiftCard.createdAt).to.equal(newGiftCard.createdAt); + expect(updatedGiftCard.code).to.equal(newGiftCard.code); + expect(updatedGiftCard.originId).to.equal(newGiftCard.originId); + expect(updatedGiftCard.originType).to.equal(newGiftCard.originType); + expect(updatedGiftCard.currency).to.equal(newGiftCard.currency); + expect(updatedGiftCard.originalBalance).to.equal(newGiftCard.originalBalance); + expect(updatedGiftCard.availableBalance).to.equal(newGiftCard.availableBalance); + expect(updatedGiftCard.currentBalance).to.equal(newGiftCard.currentBalance); + }); + + it('[bvt] Can "Cancel" a gift card', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newGiftCard = await step.createNewGiftCard(api, $.randomGiftCardPayload()); + const payload = { state: 'canceled', reasonId: 1 }; + const updatedGiftCard = await step.updateGiftCard(api, newGiftCard.code, payload); + expect(updatedGiftCard.state).to.equal(payload.state); + expect(updatedGiftCard.canceledReason).to.equal(payload.reasonId); + expect(updatedGiftCard.id).to.equal(newGiftCard.id); + expect(updatedGiftCard.createdAt).to.equal(newGiftCard.createdAt); + expect(updatedGiftCard.code).to.equal(newGiftCard.code); + expect(updatedGiftCard.originId).to.equal(newGiftCard.originId); + expect(updatedGiftCard.originType).to.equal(newGiftCard.originType); + expect(updatedGiftCard.currency).to.equal(newGiftCard.currency); + expect(updatedGiftCard.originalBalance).to.equal(newGiftCard.originalBalance); + expect(updatedGiftCard.availableBalance).to.equal(newGiftCard.availableBalance); + expect(updatedGiftCard.currentBalance).to.equal(newGiftCard.currentBalance); + expect(updatedGiftCard.canceledAmount).to.equal(newGiftCard.currentBalance); + }); + + it('[bvt] Can make gift card "Active"', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newGiftCard = await step.createNewGiftCard(api, $.randomGiftCardPayload()); + const updatedGiftCardOnHold = await step.updateGiftCard(api, newGiftCard.code, { state: 'onHold' }); + expect(updatedGiftCardOnHold.state).to.equal('onHold'); + const updatedActiveGiftCard = await step.updateGiftCard(api, newGiftCard.code, { state: 'active' }); + expect(updatedActiveGiftCard.state).to.equal('active'); + }); + + if (config.testGiftCardFlow) { + it('[bvt] Can send gift card to a customer', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const credentials = $.randomUserCredentials(); + const newCustomer = await step.createNewCustomer(api, credentials); + const newCard = await createCreditCard(api, newCustomer.id); + const inventory = await step.getInventorySkuCode(api, $.testGiftCardSkuCode); + const stockItemId = inventory.summary.find(item => item.type === 'Sellable').stockItem.id; + await step.incrementInventories(api, stockItemId, { qty: 1, status: 'onHand', type: 'Sellable' }); + const customerApi = new CustomerApi; + await step.login(customerApi, credentials.email, credentials.password, $.customerOrg); + await step.getCurrentCart(customerApi); + const giftCardAttributes = $.randomGiftCardAttributes({ senderName: credentials.name }); + await step.addSkuToCart(customerApi, $.testGiftCardSkuCode, 1, giftCardAttributes); + await step.setShippingAddress(customerApi, $.randomCreateAddressPayload()); + const shippingMethod = $.randomArrayElement(await step.getShippingMethods(customerApi)); + await step.chooseShippingMethod(customerApi, shippingMethod.id); + await step.addCreditCard(customerApi, newCard.id); + const fullOrder = await step.checkout(customerApi); + await step.updateOrder(api, fullOrder.referenceNumber, { state: 'fulfillmentStarted' }); + await step.updateOrder(api, fullOrder.referenceNumber, { state: 'shipped' }); + const newGiftCardCode = await waitFor(500, 10000, () => + step.getOrder(api, fullOrder.referenceNumber) + .then(r => r.result.lineItems.skus[0].attributes.giftCard.code), + isString); + const foundGiftCard = await step.getGiftCard(api, newGiftCardCode); + expect(foundGiftCard.message).to.equal(giftCardAttributes.giftCard.message); + expect(foundGiftCard.recipientName).to.equal(giftCardAttributes.giftCard.recipientName); + expect(foundGiftCard.recipientEmail).to.equal(giftCardAttributes.giftCard.recipientEmail); + expect(foundGiftCard.senderName).to.equal(giftCardAttributes.giftCard.senderName); + }); + } + + testNotes({ + objectType: 'gift-card', + createObject: api => step.createNewGiftCard(api, $.randomGiftCardPayload()), + selectId: giftCard => giftCard.code, + }); +}); diff --git a/build-tests/test/order.spec.js b/build-tests/test/order.spec.js new file mode 100644 index 0000000000..1d97d307b1 --- /dev/null +++ b/build-tests/test/order.spec.js @@ -0,0 +1,102 @@ +import testNotes from './test-notes'; +import testWatchers from './test-watchers'; +import { AdminApi } from '../helpers/Api'; +import placeRandomOrder from '../helpers/placeRandomOrder'; +import waitFor from '../helpers/waitFor'; +import isArray from '../helpers/isArray'; +import isString from '../helpers/isString'; +import isNumber from '../helpers/isNumber'; +import isDate from '../helpers/isDate'; +import $ from '../payloads'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +describe('Order', function() { + this.timeout(35000); + + it('[bvt] Can view order details', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const { fullOrder } = await placeRandomOrder(); + const foundOrder = await step.getOrder(api, fullOrder.referenceNumber).then(r => r.result); + delete fullOrder.fraudScore; + delete foundOrder.fraudScore; + expect(foundOrder).to.deep.equal(fullOrder); + }); + +for (const destinationState of $.orderStateTransitions.remorseHold) { + this.timeout(35000); + it(`[bvt] Can change order state from "remorseHold" to "${destinationState}"`, async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const { fullOrder } = await placeRandomOrder(); + expect(fullOrder.orderState).to.equal('remorseHold'); + const updatedOrder = await step.updateOrder(api, fullOrder.referenceNumber, { state: destinationState }); + expect(updatedOrder.orderState).to.equal(destinationState); + const foundOrder = await step.getOrder(api, fullOrder.referenceNumber).then(r => r.result); + expect(foundOrder).to.deep.equal(updatedOrder); + }); +} + +for (const destinationState of $.orderStateTransitions.fulfillmentStarted) { + this.timeout(35000); + it(`[bvt] Can change order state from "fulfillmentStarted" to "${destinationState}"`, async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const { fullOrder } = await placeRandomOrder(); + expect(fullOrder.orderState).to.equal('remorseHold'); + await step.updateOrder(api, fullOrder.referenceNumber, { state: 'fulfillmentStarted' }); + const updatedOrder = await step.updateOrder(api, fullOrder.referenceNumber, { state: destinationState }); + expect(updatedOrder.orderState).to.equal(destinationState); + const foundOrder = await step.getOrder(api, fullOrder.referenceNumber).then(r => r.result); + expect(foundOrder).to.deep.equal(updatedOrder); + }); +} + +it('[bvt] Can increase remorse period', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const { fullOrder } = await placeRandomOrder(); + expect(isDate(fullOrder.remorsePeriodEnd)).to.be.true; + const updatedOrder = await step.increaseRemorsePeriod(api, fullOrder.referenceNumber); + expect(isDate(updatedOrder.remorsePeriodEnd)).to.be.true; + const initialRemorsePeriodEndDate = new Date(fullOrder.remorsePeriodEnd); + const remorsePeriodEndDateAfterIncrease = new Date(updatedOrder.remorsePeriodEnd); + expect(remorsePeriodEndDateAfterIncrease > initialRemorsePeriodEndDate).to.be.true; + const foundOrder = await step.getOrder(api, fullOrder.referenceNumber).then(r => r.result); + expect(foundOrder).to.deep.equal(updatedOrder); +}); + +// TODO this one is broken, stucks on getShipments +// it('[bvt] Can view shipments', async () => { +// const api = new AdminApi; +// await step.loginAsAdmin(api); +// const { fullOrder } = await placeRandomOrder(); +// await step.updateOrder(api, fullOrder.referenceNumber, { state: 'fulfillmentStarted' }); +// const response = await waitFor(500, 10000, +// () => step.getShipments(api, fullOrder.referenceNumber), +// r => r.shipments && isArray(r.shipments) && r.shipments.length > 0); +// const shipments = response.shipments; +// expect(shipments).to.exist; +// for (const shipment of shipments) { +// expect(shipment.orderRefNum).to.equal(fullOrder.referenceNumber); +// expect(isNumber(shipment.id)).to.be.true; +// expect(isString(shipment.referenceNumber)).to.be.true; +// expect(isString(shipment.state)).to.be.true; +// } +// }); + +testWatchers({ + objectApi: api => api.orders, + createObject: () => placeRandomOrder().then(r => r.fullOrder), + selectId: order => order.referenceNumber, +}); + +testNotes({ + objectType: 'order', + createObject: () => placeRandomOrder().then(r => r.fullOrder), + selectId: order => order.referenceNumber, +}); +}); + + diff --git a/build-tests/test/shared-search.spec.js b/build-tests/test/shared-search.spec.js new file mode 100644 index 0000000000..74610038e2 --- /dev/null +++ b/build-tests/test/shared-search.spec.js @@ -0,0 +1,140 @@ +import { AdminApi } from '../helpers/Api'; +import $ from '../payloads'; +import isDate from '../helpers/isDate'; +import isArray from '../helpers/isArray'; +import isString from '../helpers/isString'; +import isNumber from '../helpers/isNumber'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +describe('Shared Search', function() { + + this.timeout(30000); + const newSharedSearchCodes = []; + + after('Remove shared searches created in tests', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + for (const code of newSharedSearchCodes) { + await step.deleteSharedSearch(api, code); + } + }); + + it('[bvt] Can list shared searches', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const sharedSearches = await step.listSharedSearch(api, 'ordersScope'); + expect(isArray(sharedSearches)).to.be.true; + for (const sharedSearch of sharedSearches) { + expect(isNumber(sharedSearch.id)).to.be.true; + expect(isNumber(sharedSearch.storeAdminId)).to.be.true; + expect(isString(sharedSearch.code)).to.be.true; + expect(isString(sharedSearch.title)).to.be.true; + expect(isString(sharedSearch.scope)).to.be.true; + expect(isDate(sharedSearch.createdAt)).to.be.true; + expect(sharedSearch.query).to.exist; + expect(sharedSearch.rawQuery).to.exist; + } + }); + + it('[bvt] Can create shared search', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const payload = $.randomSharedSearchPayload(); + const newSharedSearch = await step.createNewSharedSearch(api, payload); + expect(isString(newSharedSearch.code)).to.be.true; + newSharedSearchCodes.push(newSharedSearch.code); + expect(isNumber(newSharedSearch.id)).to.be.true; + expect(isNumber(newSharedSearch.storeAdminId)).to.be.true; + expect(isString(newSharedSearch.title)).to.be.true; + expect(isString(newSharedSearch.scope)).to.be.true; + expect(isDate(newSharedSearch.createdAt)).to.be.true; + expect(newSharedSearch.query).to.exist; + expect(newSharedSearch.rawQuery).to.exist; + }); + + it('[bvt] Can view shared search details', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const payload = $.randomSharedSearchPayload(); + const newSharedSearch = await step.createNewSharedSearch(api, payload); + expect(isString(newSharedSearch.code)).to.be.true; + newSharedSearchCodes.push(newSharedSearch.code); + const foundSharedSearch = await step.getSharedSearch(api, newSharedSearch.code); + expect(foundSharedSearch).to.deep.equal(newSharedSearch); + }); + + it('[bvt] Can delete shared search', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const payload = $.randomSharedSearchPayload(); + const newSharedSearch = await step.createNewSharedSearch(api, payload); + await step.deleteSharedSearch(api, newSharedSearch.code); + try { + await step.getSharedSearch(api, newSharedSearch.code); + expect('Shared search was found after deletion.').to.fail; + } catch (error) { + if (error && error.response) { + expect(error.response.status).to.equal(404); + expect(error.response.clientError).to.exist; + expect(error.response.serverError).to.be.false; + } else { + throw error; + } + } + }); + + it('[bvt] Can list associates', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const payload = $.randomSharedSearchPayload(); + const newSharedSearch = await step.createNewSharedSearch(api, payload); + expect(isString(newSharedSearch.code)).to.be.true; + newSharedSearchCodes.push(newSharedSearch.code); + const associates = await step.getAssociates(api, newSharedSearch.code); + expect(isArray(associates)).to.be.true; + for (const associate of associates) { + expect(isNumber(associate.id)).to.be.true; + expect(isString(associate.email)).to.be.true; + expect(isString(associate.name)).to.be.true; + expect(isDate(associate.createdAt)).to.be.true; + } + }); + + it('[bvt] Can add associate', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const payload = $.randomSharedSearchPayload(); + const newSharedSearch = await step.createNewSharedSearch(api, payload); + expect(isString(newSharedSearch.code)).to.be.true; + newSharedSearchCodes.push(newSharedSearch.code); + const newStoreAdmin = await step.createAdminUser(api, $.randomStoreAdminPayload()); + const associationPayload = { associates: [newStoreAdmin.id] }; + const updatedSharedSearch = await step + .addAssociate(api, newSharedSearch.code, associationPayload) + .then(r => r.result); + expect(updatedSharedSearch).to.deep.equal(newSharedSearch); + const associates = await step.getAssociates(api, newSharedSearch.code); + expect(associates.length > 0).to.be.true; + const newAssociate = associates.find(a => a.id === newStoreAdmin.id); + expect(newAssociate.id).to.equal(newStoreAdmin.id); + expect(newAssociate.name).to.equal(newStoreAdmin.name); + expect(newAssociate.email).to.equal(newStoreAdmin.email); + }); + + it('[bvt] Can remove associate', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const payload = $.randomSharedSearchPayload(); + const newSharedSearch = await step.createNewSharedSearch(api, payload); + expect(isString(newSharedSearch.code)).to.be.true; + newSharedSearchCodes.push(newSharedSearch.code); + const newStoreAdmin = await step.createAdminUser(api, $.randomStoreAdminPayload()); + const associationPayload = { associates: [newStoreAdmin.id] }; + await step.addAssociate(api, newSharedSearch.code, associationPayload); + await step.removeAssociate(api, newSharedSearch.code, newStoreAdmin.id); + const associates = await step.getAssociates(api, newSharedSearch.code); + expect(associates.find(associate => associate.id === newStoreAdmin.id)).to.not.exist; + }); + +}); diff --git a/build-tests/test/store-admin.spec.js b/build-tests/test/store-admin.spec.js new file mode 100644 index 0000000000..444c65c950 --- /dev/null +++ b/build-tests/test/store-admin.spec.js @@ -0,0 +1,68 @@ +import { AdminApi } from '../helpers/Api'; +import isNumber from '../helpers/isNumber'; +import isString from '../helpers/isString'; +import isArray from '../helpers/isArray'; +import isDate from '../helpers/isDate'; +import $ from '../payloads'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +describe('[bvt] Store Admins', function() { + + this.timeout(8000); + + it('[bvt] Can list store admins', async () => { + const api = new AdminApi; + await step.login(api, $.adminEmail, $.adminPassword, $.adminOrg); + const storeAdmins = await step.getStoreAdmins(api); + + expect(isArray(storeAdmins)); + expect(storeAdmins.length >= 1); + for (const storeAdmin of storeAdmins) { + expect(isNumber(storeAdmin.id)).to.be.true; + expect(isString(storeAdmin.name)).to.be.true; + expect(isString(storeAdmin.email)).to.be.true; + expect(isString(storeAdmin.state)).to.be.true; + expect(isString(storeAdmin.scope)).to.be.true; + expect(isDate(storeAdmin.createdAt)).to.be.true; + } + }); + + it('[bvt] Can view store admin details', async () => { + const api = new AdminApi; + await step.login(api, $.adminEmail, $.adminPassword, $.adminOrg); + const storeAdmins = await step.getStoreAdmins(api); + const storeAdmin = await step.getStoreAdmin(api, storeAdmins); + + expect(isNumber(storeAdmin.id)).to.be.true; + expect(isString(storeAdmin.name)).to.be.true; + expect(isString(storeAdmin.email)).to.be.true; + expect(isString(storeAdmin.state)).to.be.true; + }); + + it('[bvt] Can create a new store admin', async () => { + const api = new AdminApi; + await step.login(api, $.adminEmail, $.adminPassword, $.adminOrg); + const payload = $.randomStoreAdminPayload(); + const adminUser = await step.createAdminUser(api, payload); + + expect(isNumber(adminUser.id)); + expect(adminUser.state).to.equal('invited'); + expect(adminUser.name).to.equal(payload.name); + expect(adminUser.email).to.equal(payload.email); + }); + + it('[bvt] Can update store admin details', async () => { + const api = new AdminApi; + await step.login(api, $.adminEmail, $.adminPassword, $.adminOrg); + const adminUser = await step.createAdminUser(api, $.randomStoreAdminPayload()); + const updPayload = $.randomStoreAdminPayload(); + const updatedAdminUser = await step.updateAdminUser(api, adminUser.id, updPayload); + + expect(updatedAdminUser.id).to.equal(adminUser.id); + expect(updatedAdminUser.state).to.equal(adminUser.state); + expect(updatedAdminUser.name).to.equal(updPayload.name); + expect(updatedAdminUser.email).to.equal(updPayload.email); + }); + +}); \ No newline at end of file diff --git a/build-tests/test/storefront.spec.js b/build-tests/test/storefront.spec.js new file mode 100644 index 0000000000..521b0ab162 --- /dev/null +++ b/build-tests/test/storefront.spec.js @@ -0,0 +1,71 @@ +import superagent from 'superagent'; +import { AdminApi, CustomerApi } from '../helpers/Api'; +import $ from '../payloads'; +import config from '../config'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +describe('Storefront', function() { + + this.timeout(30000); + + for (const storefront of config.storefronts) { + it(`[bvt] Can access ${storefront.name} storefront`, async () => { + const response = await step.getPage(storefront.url); + expect(response.status).to.equal(200); + }); + + it(`[bvt] Can access ${storefront.name} login page`, async () => { + const response = await step.getPage(`${storefront.url}/?auth=LOGIN`); + expect(response.status).to.equal(200); + }); + + it(`[bvt] Can access ${storefront.name} sign up page`, async () => { + const response = await step.getPage(`${storefront.url}/?auth=SIGNUP`); + expect(response.status).to.equal(200); + }); + + if (storefront.aboutPagePath) { + it(`[bvt] Can access ${storefront.name} "About Us" page`, async () => { + const response = await step.getPage(`${storefront.url}/${storefront.aboutPagePath}`); + expect(response.status).to.equal(200); + }); + } + + for (const category of storefront.categories) { + it(`[bvt] Can access ${storefront.name} category "${category}"`, async () => { + const response = await step.getPage(`${storefront.url}/${encodeURIComponent(category)}`); + expect(response.status).to.equal(200); + }); + } + + it(`Can access ${storefront.name} profile page`, async () => { + const unauthorisedResponse = await step.getPage(`${storefront.url}/profile`); + expect(unauthorisedResponse.status).to.equal(200); + expect(unauthorisedResponse.redirects.length).to.equal(1); + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + const authorisedResponse = await step.userGetPage(customerApi, `${storefront.url}/profile`); + expect(authorisedResponse.status).to.equal(200); + expect(authorisedResponse.redirects.length).to.equal(0); + }); + + it(`Can access ${storefront.name} product details page`, async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const payload = $.randomProductPayload(); + const newProduct = await step.createNewProduct(api, 'default', payload); + const customerApi = new CustomerApi; + await step.loginAsCustomer(customerApi); + const response = await step.userGetPage(customerApi, `${storefront.url}/products/${newProduct.id}`); + expect(response.status).to.equal(200); + }); + + it(`Can search for products in ${storefront.name}`, async () => { + const response = await step.getPage(`${storefront.url}/search/whatever`); + expect(response.status).to.equal(200); + }); + } +}); + + diff --git a/build-tests/test/test-notes.js b/build-tests/test/test-notes.js new file mode 100644 index 0000000000..46dc774d04 --- /dev/null +++ b/build-tests/test/test-notes.js @@ -0,0 +1,43 @@ +import { AdminApi } from '../helpers/Api'; +import $ from '../payloads'; +import isDate from '../helpers/isDate'; +import isArray from '../helpers/isArray'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +export default ({ objectType, createObject, selectId = obj => obj.id }) => { + it('[bvt] Can list notes', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newObject = await createObject(api); + const notes = await step.getNotes(api, objectType, selectId(newObject)); + expect(isArray(notes)).to.be.true; + }); + + it('[bvt] Can create a new note', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newObject = await createObject(api); + const payload = $.randomCreateNotePayload(); + const newNote = await step.newNote(api, objectType, selectId(newObject), payload); + expect(newNote.id).to.exist; + expect(newNote.body).to.equal(payload.body); + expect(newNote.author.name).to.equal($.adminName); + expect(newNote.author.email).to.equal($.adminEmail); + expect(isDate(newNote.createdAt)).to.be.true; + }); + + it('[bvt] Can update note details', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newObject = await createObject(api); + const newNote = await step.newNote(api, objectType, selectId(newObject), $.randomCreateNotePayload()); + const payload = $.randomUpdateNotePayload(); + const updatedNote = await step.updateNote(api, objectType, selectId(newObject), newNote.id, payload); + expect(updatedNote.id).to.exist; + expect(updatedNote.body).to.equal(payload.body); + expect(updatedNote.author.name).to.equal($.adminName); + expect(updatedNote.author.email).to.equal($.adminEmail); + expect(isDate(updatedNote.createdAt)).to.be.true; + }); +}; diff --git a/build-tests/test/test-watchers.js b/build-tests/test/test-watchers.js new file mode 100644 index 0000000000..95d733fc01 --- /dev/null +++ b/build-tests/test/test-watchers.js @@ -0,0 +1,63 @@ +import { AdminApi } from '../helpers/Api'; +import $ from '../payloads'; +import isDate from '../helpers/isDate'; +import isArray from '../helpers/isArray'; +import { expect } from 'chai'; +import * as step from '../helpers/steps'; + +export default ({ objectApi, createObject, selectId }) => { + it('[bvt] Can list watchers', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newObject = await createObject(api); + const id = selectId(newObject); + const watchers = await objectApi(api).getWatchers(id); + expect(isArray(watchers)).to.be.true; + expect(watchers.length).to.equal(0); + }); + + it('[bvt] Can add watcher', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newObject = await createObject(api); + const storeAdmins = await step.getStoreAdmins(api); + const watcher = $.randomArrayElement(storeAdmins); + const watchersPayload = { assignees: [watcher.id] }; + const id = selectId(newObject); + const watchers = await objectApi(api).addWatchers(id, watchersPayload).then(r => r.result); + expect(isArray(watchers)).to.be.true; + expect(watchers.length).to.equal(1); + expect(isDate(watchers[0].createdAt)).to.be.true; + + // commented since of bug with assigning watcher #1993 + // t.is(watchers[0].assignee.id, watcher.id); + + expect(watchers[0].assignmentType).to.equal('watcher'); + }); + + it('[bvt] Can remove watcher', async () => { + const api = new AdminApi; + await step.loginAsAdmin(api); + const newObject = await createObject(api); + const storeAdmins = await step.getStoreAdmins(api) + const watcherId = $.randomArrayElement(storeAdmins).id; + const watchersPayload = { assignees: [watcherId] }; + const id = selectId(newObject); + const watchersAfterAdd = await objectApi(api).addWatchers(id, watchersPayload).then(r => r.result); + expect(isArray(watchersAfterAdd)).to.be.true; + expect(watchersAfterAdd.length).to.equal(1); + + // dont work since of bug with assigning watcher #1993 + // await objectApi(adminApi).removeWatcher(id, watcherId); + // const watchersAfterRemove = await objectApi(adminApi).getWatchers(id); + // t.truthy(isArray(watchersAfterRemove)); + // t.is(watchersAfterRemove.length, 0); + + // temporary remove action + const tempRemoveId = watchersAfterAdd[0].assignee.id; + await objectApi(api).removeWatcher(id, tempRemoveId); + const watchersAfterRemove = await objectApi(api).getWatchers(id); + expect(isArray(watchersAfterRemove)).to.be.true; + expect(watchersAfterRemove.length, 0).to.equal(0); + }); +}; diff --git a/build-tests/tests/auth.test.js b/build-tests/tests/bvt/auth.test.js similarity index 81% rename from build-tests/tests/auth.test.js rename to build-tests/tests/bvt/auth.test.js index d520794df8..0e845bf5cb 100644 --- a/build-tests/tests/auth.test.js +++ b/build-tests/tests/bvt/auth.test.js @@ -1,11 +1,11 @@ -import test from '../helpers/test'; -import { CustomerApi, AdminApi } from '../helpers/Api'; -import isString from '../helpers/isString'; -import isNumber from '../helpers/isNumber'; -import isDate from '../helpers/isDate'; -import $ from '../payloads'; +import test from '../../helpers/test'; +import { CustomerApi, AdminApi } from '../../helpers/Api'; +import isString from '../../helpers/isString'; +import isNumber from '../../helpers/isNumber'; +import isDate from '../../helpers/isDate'; +import $ from '../../payloads'; -test('Can sign up', async (t) => { +test('[bvt] Can sign up', async (t) => { const api = new CustomerApi(t); const { email, name, password } = $.randomUserCredentials(); const signupResponse = await api.auth.signup(email, name, password); @@ -23,7 +23,7 @@ test('Can sign up', async (t) => { t.is(signupResponse.user.storeCreditTotals.currentBalance, 0); }); -test('Can sign in as customer', async (t) => { +test('[bvt] Can sign in as customer', async (t) => { const api = new CustomerApi(t); const { email, name, password } = $.randomUserCredentials(); await api.auth.signup(email, name, password); @@ -33,7 +33,7 @@ test('Can sign in as customer', async (t) => { t.is(loginResponse.user.email, email, 'Email in login response doesn\'t match real user email.'); }); -test('Can sign in as admin', async (t) => { +test('[bvt] Can sign in as admin', async (t) => { const api = new AdminApi(t); const loginResponse = await api.auth.login($.adminEmail, $.adminPassword, $.adminOrg); t.truthy(loginResponse.jwt, 'Login response should have a "jwt" field.'); @@ -41,7 +41,7 @@ test('Can sign in as admin', async (t) => { t.truthy(loginResponse.user && loginResponse.user.email, 'Login response should have an "user.email" field.'); }); -test('Can\'t sign in as admin with a customer org', async (t) => { +test('[bvt] Can\'t sign in as admin with a customer org', async (t) => { const api = new AdminApi(t); try { await api.auth.login($.adminEmail, $.adminPassword, $.customerOrg); @@ -57,13 +57,13 @@ test('Can\'t sign in as admin with a customer org', async (t) => { } }); -test('Can sign out', async (t) => { +test('[bvt] Can sign out', async (t) => { const api = new CustomerApi(t); await api.auth.login($.adminEmail, $.adminPassword, $.adminOrg); await api.auth.logout(); }); -test('Can view customer account details', async (t) => { +test('[bvt] Can view customer account details', async (t) => { const api = new CustomerApi(t); const { email, name, password } = $.randomUserCredentials(); const signupResponse = await api.auth.signup(email, name, password); diff --git a/build-tests/tests/cart.test.js b/build-tests/tests/bvt/cart.test.js similarity index 91% rename from build-tests/tests/cart.test.js rename to build-tests/tests/bvt/cart.test.js index fadd3129b5..a1c51a922f 100644 --- a/build-tests/tests/cart.test.js +++ b/build-tests/tests/bvt/cart.test.js @@ -1,14 +1,15 @@ -import test from '../helpers/test'; -import createCreditCard from '../helpers/createCreditCard'; -import placeRandomOrder from '../helpers/placeRandomOrder'; -import { AdminApi, CustomerApi } from '../helpers/Api'; -import isArray from '../helpers/isArray'; -import isString from '../helpers/isString'; -import isNumber from '../helpers/isNumber'; -import isDate from '../helpers/isDate'; -import $ from '../payloads'; +/* eslint-disable no-trailing-spaces */ +import test from '../../helpers/test'; +import createCreditCard from '../../helpers/createCreditCard'; +import placeRandomOrder from '../../helpers/placeRandomOrder'; +import { AdminApi, CustomerApi } from '../../helpers/Api'; +import isArray from '../../helpers/isArray'; +import isString from '../../helpers/isString'; +import isNumber from '../../helpers/isNumber'; +import isDate from '../../helpers/isDate'; +import $ from '../../payloads'; -test('Can add line item', async (t) => { +test('[bvt] Can add line item', async (t) => { const adminApi = await AdminApi.loggedIn(t); const productPayload = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); const newProduct = await adminApi.products.create('default', productPayload); @@ -27,7 +28,7 @@ test('Can add line item', async (t) => { // t.deepEqual(foundOrder, fullOrder); }); -test('Can update line item', async (t) => { +test('[bvt] Can update line item', async (t) => { const adminApi = await AdminApi.loggedIn(t); const productPayload = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); const newProduct = await adminApi.products.create('default', productPayload); @@ -47,7 +48,7 @@ test('Can update line item', async (t) => { // t.deepEqual(foundOrder, fullOrder); }); -test('Can remove line item', async (t) => { +test('[bvt] Can remove line item', async (t) => { const adminApi = await AdminApi.loggedIn(t); const productPayload = $.randomProductPayload({ minSkus: 1, maxSkus: 1 }); const newProduct = await adminApi.products.create('default', productPayload); @@ -63,7 +64,7 @@ test('Can remove line item', async (t) => { t.deepEqual(foundOrder, fullOrder); }); -test('Can set shipping address', async (t) => { +test('[bvt] Can set shipping address', async (t) => { const customerApi = await CustomerApi.loggedIn(t); await customerApi.cart.get(); const payload = $.randomCreateAddressPayload(); @@ -81,7 +82,7 @@ test('Can set shipping address', async (t) => { t.deepEqual(foundOrder, fullOrder); }); -test('Can list available shipping methods', async (t) => { +test('[bvt] Can list available shipping methods', async (t) => { const customerApi = await CustomerApi.loggedIn(t); await customerApi.cart.get(); await customerApi.cart.setShippingAddress($.randomCreateAddressPayload()); @@ -95,7 +96,7 @@ test('Can list available shipping methods', async (t) => { } }); -test('Can choose shipping method', async (t) => { +test('[bvt] Can choose shipping method', async (t) => { const customerApi = await CustomerApi.loggedIn(t); await customerApi.cart.get(); await customerApi.cart.setShippingAddress($.randomCreateAddressPayload()); @@ -107,7 +108,7 @@ test('Can choose shipping method', async (t) => { t.deepEqual(foundOrder, fullOrder); }); -test('Can apply credit card', async (t) => { +test('[bvt] Can apply credit card', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -132,7 +133,7 @@ test('Can apply credit card', async (t) => { t.deepEqual(foundOrder, fullOrder); }); -test('Can remove credit card', async (t) => { +test('[bvt] Can remove credit card', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -150,7 +151,7 @@ test('Can remove credit card', async (t) => { t.deepEqual(foundOrder, fullOrderAfterRemovingCC); }); -test('Can apply gift card', async (t) => { +test('[bvt] Can apply gift card', async (t) => { const adminApi = await AdminApi.loggedIn(t); const giftCardPayload = $.randomGiftCardPayload(); const newGiftCard = await adminApi.giftCards.create(giftCardPayload); @@ -171,7 +172,7 @@ test('Can apply gift card', async (t) => { t.deepEqual(foundOrder, fullOrder); }); -test('Can remove gift card', async (t) => { +test('[bvt] Can remove gift card', async (t) => { const adminApi = await AdminApi.loggedIn(t); const giftCardPayload = $.randomGiftCardPayload(); const newGiftCard = await adminApi.giftCards.create(giftCardPayload); @@ -188,7 +189,7 @@ test('Can remove gift card', async (t) => { t.deepEqual(foundOrder, fullOrderAfterRemovingGC); }); -test('Can apply store credit', async (t) => { +test('[bvt] Can apply store credit', async (t) => { const customerApi = await CustomerApi.loggedIn(t); const adminApi = await AdminApi.loggedIn(t); const storeCreditPayload = $.randomStoreCreditPayload(); @@ -208,7 +209,7 @@ test('Can apply store credit', async (t) => { t.deepEqual(foundOrder, fullOrder); }); -test('Can remove store credit', async (t) => { +test('[bvt] Can remove store credit', async (t) => { const customerApi = await CustomerApi.loggedIn(t); const adminApi = await AdminApi.loggedIn(t); const storeCreditPayload = $.randomStoreCreditPayload(); @@ -225,7 +226,7 @@ test('Can remove store credit', async (t) => { t.deepEqual(foundOrder, fullOrderAfterRemovingSC); }); -test('Can apply coupon', async (t) => { +test('[bvt] Can apply coupon', async (t) => { const adminApi = await AdminApi.loggedIn(t); const context = 'default'; const newPromotion = await adminApi.promotions.create(context, $.randomCreatePromotionPayload()); @@ -249,7 +250,7 @@ test('Can apply coupon', async (t) => { t.deepEqual(foundOrder, fullOrder); }); -test('Can remove coupon', async (t) => { +test('[bvt] Can remove coupon', async (t) => { const adminApi = await AdminApi.loggedIn(t); const context = 'default'; const newPromotion = await adminApi.promotions.create(context, $.randomCreatePromotionPayload()); @@ -275,7 +276,7 @@ test('Can remove coupon', async (t) => { // t.deepEqual(foundOrder, fullOrderAfterRemovingCoupon); }); -test('Can checkout a cart', async (t) => { +test('[bvt] Can checkout a cart', async (t) => { const { fullOrder, newCard, newCustomer } = await placeRandomOrder(t); t.is(fullOrder.paymentState, 'auth'); t.is(fullOrder.orderState, 'remorseHold'); @@ -292,4 +293,4 @@ test('Can checkout a cart', async (t) => { t.is(fullOrder.billingCreditCardInfo.expYear, newCard.expYear); t.is(fullOrder.billingCreditCardInfo.brand, newCard.brand); t.deepEqual(fullOrder.customer, newCustomer); -}); \ No newline at end of file +}); diff --git a/build-tests/tests/carts.test.js b/build-tests/tests/bvt/carts.test.js similarity index 89% rename from build-tests/tests/carts.test.js rename to build-tests/tests/bvt/carts.test.js index 679022beb3..2052580d91 100644 --- a/build-tests/tests/carts.test.js +++ b/build-tests/tests/bvt/carts.test.js @@ -1,15 +1,15 @@ -import test from '../helpers/test'; +import test from '../../helpers/test'; import testNotes from './testNotes'; import testWatchers from './testWatchers'; -import createCreditCard from '../helpers/createCreditCard'; -import placeRandomOrder from '../helpers/placeRandomOrder'; -import { AdminApi, CustomerApi } from '../helpers/Api'; -import isArray from '../helpers/isArray'; -import isString from '../helpers/isString'; -import isNumber from '../helpers/isNumber'; -import $ from '../payloads'; +import createCreditCard from '../../helpers/createCreditCard'; +import placeRandomOrder from '../../helpers/placeRandomOrder'; +import { AdminApi, CustomerApi } from '../../helpers/Api'; +import isArray from '../../helpers/isArray'; +import isString from '../../helpers/isString'; +import isNumber from '../../helpers/isNumber'; +import $ from '../../payloads'; -test('Can view cart details', async (t) => { +test('[bvt] Can view cart details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -38,7 +38,7 @@ test('Can view cart details', async (t) => { t.deepEqual(foundCart, cart); }); -test('Can list available shipping methods', async (t) => { +test('[bvt] Can list available shipping methods', async (t) => { const customerApi = await CustomerApi.loggedIn(t); const cart = await customerApi.cart.get(); await customerApi.cart.setShippingAddress($.randomCreateAddressPayload()); @@ -55,7 +55,7 @@ test('Can list available shipping methods', async (t) => { t.deepEqual(shippingMethodsFromAdminApi, shippingMethodsFromCustomerApi); }); -test('Can update line items', async (t) => { +test('[bvt] Can update line items', async (t) => { const customerApi = await CustomerApi.loggedIn(t); const { referenceNumber } = await customerApi.cart.get(); const adminApi = await AdminApi.loggedIn(t); @@ -77,7 +77,7 @@ test('Can update line items', async (t) => { // t.deepEqual(cart, updatedCart); }); -test('Updating one line item doesn\'t affect others', async (t) => { +test('[bvt] Updating one line item doesn\'t affect others', async (t) => { const customerApi = await CustomerApi.loggedIn(t); const { referenceNumber } = await customerApi.cart.get(); const adminApi = await AdminApi.loggedIn(t); @@ -106,7 +106,7 @@ test('Updating one line item doesn\'t affect others', async (t) => { // t.deepEqual(cart, updatedCart); }); -test('Can\'t access the cart once order for it has been placed', async (t) => { +test('[bvt] Can\'t access the cart once order for it has been placed', async (t) => { const { fullOrder } = await placeRandomOrder(t); try { const adminApi = await AdminApi.loggedIn(t); diff --git a/build-tests/tests/coupon.test.js b/build-tests/tests/bvt/coupon.test.js similarity index 85% rename from build-tests/tests/coupon.test.js rename to build-tests/tests/bvt/coupon.test.js index 73ea7456a9..0f7b2a9036 100644 --- a/build-tests/tests/coupon.test.js +++ b/build-tests/tests/bvt/coupon.test.js @@ -1,27 +1,27 @@ -import test from '../helpers/test'; +import test from '../../helpers/test'; import testNotes from './testNotes'; -import { AdminApi } from '../helpers/Api'; -import isNumber from '../helpers/isNumber'; -import isArray from '../helpers/isArray'; -import isDate from '../helpers/isDate'; -import $ from '../payloads'; +import { AdminApi } from '../../helpers/Api'; +import isNumber from '../../helpers/isNumber'; +import isArray from '../../helpers/isArray'; +import isDate from '../../helpers/isDate'; +import $ from '../../payloads'; -test('Can create a coupon', async (t) => { +test('[bvt] Can create a coupon', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newPromotion = await adminApi.promotions.create('default', $.randomCreatePromotionPayload()); const payload = $.randomCouponPayload(newPromotion.id); const newCoupon = await adminApi.coupons.create('default', payload); - // activeFrom date cannot be set for coupon due to intentional decision + // activeFrom date cannot be set for coupon due to intentional decision payload.attributes.activeFrom.v = newCoupon.attributes.activeFrom.v; - + t.truthy(isNumber(newCoupon.id)); t.is(newCoupon.promotion, newPromotion.id); t.is(newCoupon.context.name, 'default'); t.deepEqual(newCoupon.attributes, payload.attributes); }); -test('Can view coupon details', async (t) => { +test('[bvt] Can view coupon details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newPromotion = await adminApi.promotions.create('default', $.randomCreatePromotionPayload()); const newCoupon = await adminApi.coupons.create('default', $.randomCouponPayload(newPromotion.id)); @@ -29,7 +29,7 @@ test('Can view coupon details', async (t) => { t.deepEqual(foundCoupon, newCoupon); }); -test('Can update coupon details', async (t) => { +test('[bvt] Can update coupon details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newPromotion = await adminApi.promotions.create('default', $.randomCreatePromotionPayload()); const newCoupon = await adminApi.coupons.create('default', $.randomCouponPayload(newPromotion.id)); @@ -41,11 +41,11 @@ test('Can update coupon details', async (t) => { t.is(updatedCoupon.id, newCoupon.id); t.is(updatedCoupon.promotion, newPromotion.id); - t.is(updatedCoupon.context.name, 'default'); + t.is(updatedCoupon.context.name, 'default'); t.deepEqual(updatedCoupon.attributes, payload.attributes); }); -test('Can bulk generate the codes', async (t) => { +test('[bvt] Can bulk generate the codes', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newPromotion = await adminApi.promotions.create('default', $.randomCreatePromotionPayload()); const newCoupon = await adminApi.coupons.create('default', $.randomCouponPayload(newPromotion.id)); @@ -59,7 +59,7 @@ test('Can bulk generate the codes', async (t) => { } }); -test('Can view the list of coupon codes', async (t) => { +test('[bvt] Can view the list of coupon codes', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newPromotion = await adminApi.promotions.create('default', $.randomCreatePromotionPayload()); const newCoupon = await adminApi.coupons.create('default', $.randomCouponPayload(newPromotion.id)); diff --git a/build-tests/tests/customer.test.js b/build-tests/tests/bvt/customer.test.js similarity index 88% rename from build-tests/tests/customer.test.js rename to build-tests/tests/bvt/customer.test.js index 81987d8157..b640a1f4c9 100644 --- a/build-tests/tests/customer.test.js +++ b/build-tests/tests/bvt/customer.test.js @@ -1,12 +1,12 @@ -import test from '../helpers/test'; +import test from '../../helpers/test'; import testNotes from './testNotes'; -import { AdminApi } from '../helpers/Api'; -import $ from '../payloads'; -import isDate from '../helpers/isDate'; -import isArray from '../helpers/isArray'; -import isNumber from '../helpers/isNumber'; +import { AdminApi } from '../../helpers/Api'; +import $ from '../../payloads'; +import isDate from '../../helpers/isDate'; +import isArray from '../../helpers/isArray'; +import isNumber from '../../helpers/isNumber'; -test('Can create a new customer', async (t) => { +test('[bvt] Can create a new customer', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -14,7 +14,7 @@ test('Can create a new customer', async (t) => { t.is(newCustomer.email, credentials.email); }); -test('Can view customer details', async (t) => { +test('[bvt] Can view customer details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -23,7 +23,7 @@ test('Can view customer details', async (t) => { t.is(foundCustomer.email, credentials.email); }); -test('Can update customer details', async (t) => { +test('[bvt] Can update customer details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -33,7 +33,7 @@ test('Can update customer details', async (t) => { t.is(updatedCustomer.email, otherCredentials.email); }); -test('Can list shipping addresses', async (t) => { +test('[bvt] Can list shipping addresses', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -41,7 +41,7 @@ test('Can list shipping addresses', async (t) => { t.truthy(isArray(addresses)); }); -test('Can add a new shipping address', async (t) => { +test('[bvt] Can add a new shipping address', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -56,7 +56,7 @@ test('Can add a new shipping address', async (t) => { t.is(addedAddress.phoneNumber, address.phoneNumber); }); -test('Can update shipping address details', async (t) => { +test('[bvt] Can update shipping address details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -81,7 +81,7 @@ test('Can update shipping address details', async (t) => { t.is(foundAddress.phoneNumber, otherAddress.phoneNumber); }); -test('Can delete a shipping address', async (t) => { +test('[bvt] Can delete a shipping address', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -92,7 +92,7 @@ test('Can delete a shipping address', async (t) => { t.truthy(foundAddress.deletedAt); }); -test('Can list customer\'s credit cards', async (t) => { +test('[bvt] Can list customer\'s credit cards', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -100,7 +100,7 @@ test('Can list customer\'s credit cards', async (t) => { t.truthy(isArray(creditCards)); }); -test('Can add customer\'s credit card', async (t) => { +test('[bvt] Can add customer\'s credit card', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -135,7 +135,7 @@ test('Can add customer\'s credit card', async (t) => { t.is(addedCard.address.phoneNumber, payload.billingAddress.phoneNumber); }); -test('Can issue store credit', async (t) => { +test('[bvt] Can issue store credit', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); @@ -153,13 +153,13 @@ test('Can issue store credit', async (t) => { t.truthy(isDate(newStoreCredit.createdAt)); }); -test('Can list customer groups', async (t) => { +test('[bvt] Can list customer groups', async (t) => { const adminApi = await AdminApi.loggedIn(t); const customerGroups = await adminApi.customerGroups.list(); t.truthy(isArray(customerGroups)); }); -test('Can create a new customer group', async (t) => { +test('[bvt] Can create a new customer group', async (t) => { const adminApi = await AdminApi.loggedIn(t); const payload = $.randomCustomerGroupPayload(); const newCustomerGroup = await adminApi.customerGroups.create(payload); @@ -171,14 +171,14 @@ test('Can create a new customer group', async (t) => { t.deepEqual(newCustomerGroup.elasticRequest, payload.elasticRequest); }); -test('Can view customer group details', async (t) => { +test('[bvt] Can view customer group details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newCustomerGroup = await adminApi.customerGroups.create($.randomCustomerGroupPayload()); const foundCustomerGroup = await adminApi.customerGroups.one(newCustomerGroup.id); t.deepEqual(foundCustomerGroup, newCustomerGroup); }); -test('Can update customer group details', async (t) => { +test('[bvt] Can update customer group details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newCustomerGroup = await adminApi.customerGroups.create($.randomCustomerGroupPayload()); const payload = $.randomCustomerGroupPayload(); diff --git a/build-tests/tests/dev.test.js b/build-tests/tests/bvt/dev.test.js similarity index 74% rename from build-tests/tests/dev.test.js rename to build-tests/tests/bvt/dev.test.js index 2e32b23386..48d61bec1e 100644 --- a/build-tests/tests/dev.test.js +++ b/build-tests/tests/bvt/dev.test.js @@ -1,8 +1,8 @@ -import test from '../helpers/test'; -import { AdminApi } from '../helpers/Api'; -import $ from '../payloads'; +import test from '../../helpers/test'; +import { AdminApi } from '../../helpers/Api'; +import $ from '../../payloads'; -test('Can issue credit card token', async (t) => { +test('[bvt] Can issue credit card token', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); diff --git a/build-tests/tests/gift-card.test.js b/build-tests/tests/bvt/gift-card.test.js similarity index 87% rename from build-tests/tests/gift-card.test.js rename to build-tests/tests/bvt/gift-card.test.js index ea028fe164..6645894ad9 100644 --- a/build-tests/tests/gift-card.test.js +++ b/build-tests/tests/bvt/gift-card.test.js @@ -1,15 +1,15 @@ -import test from '../helpers/test'; +import test from '../../helpers/test'; import testNotes from './testNotes'; -import { AdminApi, CustomerApi } from '../helpers/Api'; -import createCreditCard from '../helpers/createCreditCard'; -import waitFor from '../helpers/waitFor'; -import isNumber from '../helpers/isNumber'; -import isString from '../helpers/isString'; -import isDate from '../helpers/isDate'; -import $ from '../payloads'; -import config from '../config'; +import { AdminApi, CustomerApi } from '../../helpers/Api'; +import createCreditCard from '../../helpers/createCreditCard'; +import waitFor from '../../helpers/waitFor'; +import isNumber from '../../helpers/isNumber'; +import isString from '../../helpers/isString'; +import isDate from '../../helpers/isDate'; +import $ from '../../payloads'; +import config from '../../config'; -test('Can create a gift card', async (t) => { +test('[bvt] Can create a gift card', async (t) => { const adminApi = await AdminApi.loggedIn(t); const payload = $.randomGiftCardPayload(); const newGiftCard = await adminApi.giftCards.create(payload); @@ -28,7 +28,7 @@ test('Can create a gift card', async (t) => { t.is(newGiftCard.storeAdmin.name, $.adminName); }); -test('Can view gift card details', async (t) => { +test('[bvt] Can view gift card details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const payload = $.randomGiftCardPayload(); const newGiftCard = await adminApi.giftCards.create(payload); @@ -36,7 +36,7 @@ test('Can view gift card details', async (t) => { t.deepEqual(foundGiftCard, newGiftCard); }); -test('Can put a gift card "On Hold"', async (t) => { +test('[bvt] Can put a gift card "On Hold"', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newGiftCard = await adminApi.giftCards.create($.randomGiftCardPayload()); const updatedGiftCard = await adminApi.giftCards.update(newGiftCard.code, { state: 'onHold' }); @@ -52,7 +52,7 @@ test('Can put a gift card "On Hold"', async (t) => { t.is(updatedGiftCard.currentBalance, newGiftCard.currentBalance); }); -test('Can "Cancel" a gift card', async (t) => { +test('[bvt] Can "Cancel" a gift card', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newGiftCard = await adminApi.giftCards.create($.randomGiftCardPayload()); const payload = { state: 'canceled', reasonId: 1 }; @@ -71,7 +71,7 @@ test('Can "Cancel" a gift card', async (t) => { t.is(updatedGiftCard.canceledAmount, newGiftCard.currentBalance); }); -test('Can make gift card "Active"', async (t) => { +test('[bvt] Can make gift card "Active"', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newGiftCard = await adminApi.giftCards.create($.randomGiftCardPayload()); const updatedGiftCardOnHold = await adminApi.giftCards.update(newGiftCard.code, { state: 'onHold' }); @@ -81,7 +81,7 @@ test('Can make gift card "Active"', async (t) => { }); if (config.testGiftCardFlow) { - test('Can send gift card to a customer', async (t) => { + test('[bvt] Can send gift card to a customer', async (t) => { const adminApi = await AdminApi.loggedIn(t); const credentials = $.randomUserCredentials(); const newCustomer = await adminApi.customers.create(credentials); diff --git a/build-tests/tests/order.test.js b/build-tests/tests/bvt/order.test.js similarity index 62% rename from build-tests/tests/order.test.js rename to build-tests/tests/bvt/order.test.js index aa603d6b6f..2ebfe814eb 100644 --- a/build-tests/tests/order.test.js +++ b/build-tests/tests/bvt/order.test.js @@ -1,16 +1,16 @@ -import test from '../helpers/test'; +import test from '../../helpers/test'; import testNotes from './testNotes'; import testWatchers from './testWatchers'; -import { AdminApi } from '../helpers/Api'; -import placeRandomOrder from '../helpers/placeRandomOrder'; -import waitFor from '../helpers/waitFor'; -import isArray from '../helpers/isArray'; -import isString from '../helpers/isString'; -import isNumber from '../helpers/isNumber'; -import isDate from '../helpers/isDate'; -import $ from '../payloads'; +import { AdminApi } from '../../helpers/Api'; +import placeRandomOrder from '../../helpers/placeRandomOrder'; +import waitFor from '../../helpers/waitFor'; +import isArray from '../../helpers/isArray'; +import isString from '../../helpers/isString'; +import isNumber from '../../helpers/isNumber'; +import isDate from '../../helpers/isDate'; +import $ from '../../payloads'; -test('Can view order details', async (t) => { +test('[bvt] Can view order details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const { fullOrder } = await placeRandomOrder(t); const foundOrder = await adminApi.orders.one(fullOrder.referenceNumber).then(r => r.result); @@ -20,7 +20,7 @@ test('Can view order details', async (t) => { }); for (const destinationState of $.orderStateTransitions.remorseHold) { - test(`Can change order state from "remorseHold" to "${destinationState}"`, async (t) => { + test(`[bvt] Can change order state from "remorseHold" to "${destinationState}"`, async (t) => { const adminApi = await AdminApi.loggedIn(t); const { fullOrder } = await placeRandomOrder(t); t.is(fullOrder.orderState, 'remorseHold'); @@ -32,7 +32,7 @@ for (const destinationState of $.orderStateTransitions.remorseHold) { } for (const destinationState of $.orderStateTransitions.fulfillmentStarted) { - test(`Can change order state from "fulfillmentStarted" to "${destinationState}"`, async (t) => { + test(`[bvt] Can change order state from "fulfillmentStarted" to "${destinationState}"`, async (t) => { const adminApi = await AdminApi.loggedIn(t); const { fullOrder } = await placeRandomOrder(t); t.is(fullOrder.orderState, 'remorseHold'); @@ -44,7 +44,7 @@ for (const destinationState of $.orderStateTransitions.fulfillmentStarted) { }); } -test('Can increase remorse period', async (t) => { +test('[bvt] Can increase remorse period', async (t) => { const adminApi = await AdminApi.loggedIn(t); const { fullOrder } = await placeRandomOrder(t); t.truthy(isDate(fullOrder.remorsePeriodEnd)); @@ -57,23 +57,22 @@ test('Can increase remorse period', async (t) => { t.deepEqual(foundOrder, updatedOrder); }); -// the following test is successful in STAGE-TPG, but not in STAGE where shipstation is not connected -// test('Can view shipments', async (t) => { -// const adminApi = await AdminApi.loggedIn(t); -// const { fullOrder } = await placeRandomOrder(t); -// await adminApi.orders.update(fullOrder.referenceNumber, { state: 'fulfillmentStarted' }); -// const response = await waitFor(500, 10000, -// () => adminApi.inventories.getShipments(fullOrder.referenceNumber), -// r => r.shipments && isArray(r.shipments) && r.shipments.length > 0); -// const shipments = response.shipments; -// t.truthy(shipments); -// for (const shipment of shipments) { -// t.is(shipment.orderRefNum, fullOrder.referenceNumber); -// t.truthy(isNumber(shipment.id)); -// t.truthy(isString(shipment.referenceNumber)); -// t.truthy(isString(shipment.state)); -// } -// }); +test('[bvt] Can view shipments', async (t) => { + const adminApi = await AdminApi.loggedIn(t); + const { fullOrder } = await placeRandomOrder(t); + await adminApi.orders.update(fullOrder.referenceNumber, { state: 'fulfillmentStarted' }); + const response = await waitFor(500, 10000, + () => adminApi.inventories.getShipments(fullOrder.referenceNumber), + r => r.shipments && isArray(r.shipments) && r.shipments.length > 0); + const shipments = response.shipments; + t.truthy(shipments); + for (const shipment of shipments) { + t.is(shipment.orderRefNum, fullOrder.referenceNumber); + t.truthy(isNumber(shipment.id)); + t.truthy(isString(shipment.referenceNumber)); + t.truthy(isString(shipment.state)); + } +}); testWatchers({ objectApi: api => api.orders, diff --git a/build-tests/tests/product.test.js b/build-tests/tests/bvt/product.test.js similarity index 89% rename from build-tests/tests/product.test.js rename to build-tests/tests/bvt/product.test.js index 10f35b5013..9c201d9db0 100644 --- a/build-tests/tests/product.test.js +++ b/build-tests/tests/bvt/product.test.js @@ -1,13 +1,13 @@ -import test from '../helpers/test'; +import test from '../../helpers/test'; import testNotes from './testNotes'; -import { AdminApi } from '../helpers/Api'; -import isNumber from '../helpers/isNumber'; -import isString from '../helpers/isString'; -import isDate from '../helpers/isDate'; -import isArray from '../helpers/isArray'; -import $ from '../payloads'; +import { AdminApi } from '../../helpers/Api'; +import isNumber from '../../helpers/isNumber'; +import isString from '../../helpers/isString'; +import isDate from '../../helpers/isDate'; +import isArray from '../../helpers/isArray'; +import $ from '../../payloads'; -test('Can create a product', async (t) => { +test('[bvt] Can create a product', async (t) => { const adminApi = await AdminApi.loggedIn(t); const payload = $.randomProductPayload(); const newProduct = await adminApi.products.create('default', payload); @@ -29,21 +29,21 @@ test('Can create a product', async (t) => { } }); -test('Can archive a product', async (t) => { +test('[bvt] Can archive a product', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newProduct = await adminApi.products.create('default', $.randomProductPayload()); const archivedProduct = await adminApi.products.archive('default', newProduct.id); t.truthy(isDate(archivedProduct.archivedAt)); }); -test('Can view product details', async (t) => { +test('[bvt] Can view product details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newProduct = await adminApi.products.create('default', $.randomProductPayload()); const foundProduct = await adminApi.products.one('default', newProduct.id); t.deepEqual(foundProduct, newProduct); }); -test('Can update product details', async (t) => { +test('[bvt] Can update product details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newProduct = await adminApi.products.create('default', $.randomProductPayload()); const payload = $.randomProductPayload(); @@ -65,7 +65,7 @@ test('Can update product details', async (t) => { } }); -test('Can create an album', async (t) => { +test('[bvt] Can create an album', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newProduct = await adminApi.products.create('default', $.randomProductPayload()); const payload = $.randomAlbumPayload(); @@ -83,7 +83,7 @@ test('Can create an album', async (t) => { } }); -test('Can update album details', async (t) => { +test('[bvt] Can update album details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newProduct = await adminApi.products.create('default', $.randomProductPayload()); const newAlbum = await adminApi.productAlbums.create('default', newProduct.id, $.randomAlbumPayload()); @@ -104,7 +104,7 @@ test('Can update album details', async (t) => { } }); -test('Can archive an album', async (t) => { +test('[bvt] Can archive an album', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newProduct = await adminApi.products.create('default', $.randomProductPayload()); const newAlbum = await adminApi.productAlbums.create('default', newProduct.id, $.randomAlbumPayload()); @@ -112,7 +112,7 @@ test('Can archive an album', async (t) => { t.truthy(isDate(archivedAlbum.archivedAt)); }); -test('Can upload an image', async (t) => { +test('[bvt] Can upload an image', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newProduct = await adminApi.products.create('default', $.randomProductPayload()); const newAlbum = await adminApi.productAlbums.create('default', newProduct.id, $.randomAlbumPayload()); @@ -130,7 +130,7 @@ test('Can upload an image', async (t) => { t.truthy(isString(newImage.title)); }); -test('Can update image details', async (t) => { +test('[bvt] Can update image details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newProduct = await adminApi.products.create('default', $.randomProductPayload()); const newAlbum = await adminApi.productAlbums.create('default', newProduct.id, $.randomAlbumPayload({ minImages: 1 })); @@ -143,7 +143,7 @@ test('Can update image details', async (t) => { t.is(updatedAlbum.images[0].title, payload.title); }); -test('Can delete an image', async (t) => { +test('[bvt] Can delete an image', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newProduct = await adminApi.products.create('default', $.randomProductPayload()); const newAlbum = await adminApi.productAlbums.create('default', newProduct.id, $.randomAlbumPayload({ minImages: 1 })); diff --git a/build-tests/tests/promotion.test.js b/build-tests/tests/bvt/promotion.test.js similarity index 86% rename from build-tests/tests/promotion.test.js rename to build-tests/tests/bvt/promotion.test.js index e192ebe862..ea1cfcf827 100644 --- a/build-tests/tests/promotion.test.js +++ b/build-tests/tests/bvt/promotion.test.js @@ -1,11 +1,11 @@ -import test from '../helpers/test'; +import test from '../../helpers/test'; import testNotes from './testNotes'; -import { AdminApi } from '../helpers/Api'; -import isNumber from '../helpers/isNumber'; -import isDate from '../helpers/isDate'; -import $ from '../payloads'; +import { AdminApi } from '../../helpers/Api'; +import isNumber from '../../helpers/isNumber'; +import isDate from '../../helpers/isDate'; +import $ from '../../payloads'; -test('Can create a promotion', async (t) => { +test('[bvt] Can create a promotion', async (t) => { const adminApi = await AdminApi.loggedIn(t); const payload = $.randomCreatePromotionPayload(); const newPromotion = await adminApi.promotions.create('default', payload); @@ -26,14 +26,14 @@ test('Can create a promotion', async (t) => { } }); -test('Can view promotion details', async (t) => { +test('[bvt] Can view promotion details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newPromotion = await adminApi.promotions.create('default', $.randomCreatePromotionPayload()); const foundPromotion = await adminApi.promotions.one('default', newPromotion.id); t.deepEqual(foundPromotion, newPromotion); }); -test('Can update promotion details', async (t) => { +test('[bvt] Can update promotion details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newPromotion = await adminApi.promotions.create('default', $.randomCreatePromotionPayload()); const payload = $.randomUpdatePromotionPayload(newPromotion.discounts.map(d => d.id)); diff --git a/build-tests/tests/shared-search.test.js b/build-tests/tests/bvt/shared-search.test.js similarity index 85% rename from build-tests/tests/shared-search.test.js rename to build-tests/tests/bvt/shared-search.test.js index 7116e0cfa3..09f67f47f4 100644 --- a/build-tests/tests/shared-search.test.js +++ b/build-tests/tests/bvt/shared-search.test.js @@ -1,22 +1,22 @@ import ava from 'ava'; -import test from '../helpers/test'; -import { AdminApi } from '../helpers/Api'; -import $ from '../payloads'; -import isDate from '../helpers/isDate'; -import isArray from '../helpers/isArray'; -import isString from '../helpers/isString'; -import isNumber from '../helpers/isNumber'; +import test from '../../helpers/test'; +import { AdminApi } from '../../helpers/Api'; +import $ from '../../payloads'; +import isDate from '../../helpers/isDate'; +import isArray from '../../helpers/isArray'; +import isString from '../../helpers/isString'; +import isNumber from '../../helpers/isNumber'; const newSharedSearchCodes = []; -ava.always.after('Remove shared searches created in tests', async () => { +ava.always.after('[bvt] Remove shared searches created in tests', async () => { const adminApi = await AdminApi.loggedIn(); for (const code of newSharedSearchCodes) { await adminApi.sharedSearches.delete(code); } }); -test('Can list shared searches', async (t) => { +test('[bvt] Can list shared searches', async (t) => { const adminApi = await AdminApi.loggedIn(t); const sharedSearches = await adminApi.sharedSearches.list('ordersScope'); t.truthy(isArray(sharedSearches)); @@ -32,7 +32,7 @@ test('Can list shared searches', async (t) => { } }); -test('Can create shared search', async (t) => { +test('[bvt] Can create shared search', async (t) => { const adminApi = await AdminApi.loggedIn(t); const payload = $.randomSharedSearchPayload(); const newSharedSearch = await adminApi.sharedSearches.create(payload); @@ -47,7 +47,7 @@ test('Can create shared search', async (t) => { t.truthy(newSharedSearch.rawQuery); }); -test('Can view shared search details', async (t) => { +test('[bvt] Can view shared search details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const payload = $.randomSharedSearchPayload(); const newSharedSearch = await adminApi.sharedSearches.create(payload); @@ -57,7 +57,7 @@ test('Can view shared search details', async (t) => { t.deepEqual(foundSharedSearch, newSharedSearch); }); -test('Can delete shared search', async (t) => { +test('[bvt] Can delete shared search', async (t) => { const adminApi = await AdminApi.loggedIn(t); const payload = $.randomSharedSearchPayload(); const newSharedSearch = await adminApi.sharedSearches.create(payload); @@ -76,7 +76,7 @@ test('Can delete shared search', async (t) => { } }); -test('Can list associates', async (t) => { +test('[bvt] Can list associates', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newSharedSearch = await adminApi.sharedSearches.create($.randomSharedSearchPayload()); t.truthy(isString(newSharedSearch.code)); @@ -91,7 +91,7 @@ test('Can list associates', async (t) => { } }); -test('Can add associate', async (t) => { +test('[bvt] Can add associate', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newSharedSearch = await adminApi.sharedSearches.create($.randomSharedSearchPayload()); t.truthy(isString(newSharedSearch.code)); @@ -109,7 +109,7 @@ test('Can add associate', async (t) => { t.is(newAssociate.email, newStoreAdmin.email); }); -test('Can remove associate', async (t) => { +test('[bvt] Can remove associate', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newSharedSearch = await adminApi.sharedSearches.create($.randomSharedSearchPayload()); t.truthy(isString(newSharedSearch.code)); diff --git a/build-tests/tests/sku.test.js b/build-tests/tests/bvt/sku.test.js similarity index 82% rename from build-tests/tests/sku.test.js rename to build-tests/tests/bvt/sku.test.js index 96a1f275b5..df3746f6b5 100644 --- a/build-tests/tests/sku.test.js +++ b/build-tests/tests/bvt/sku.test.js @@ -1,13 +1,13 @@ -import test from '../helpers/test'; +import test from '../../helpers/test'; import testNotes from './testNotes'; -import { AdminApi } from '../helpers/Api'; -import isNumber from '../helpers/isNumber'; -import isDate from '../helpers/isDate'; -import isArray from '../helpers/isArray'; -import waitFor from '../helpers/waitFor'; -import $ from '../payloads'; +import { AdminApi } from '../../helpers/Api'; +import isNumber from '../../helpers/isNumber'; +import isDate from '../../helpers/isDate'; +import isArray from '../../helpers/isArray'; +import waitFor from '../../helpers/waitFor'; +import $ from '../../payloads'; -test('Can create a new SKU', async (t) => { +test('[bvt] Can create a new SKU', async (t) => { const adminApi = await AdminApi.loggedIn(t); const payload = $.randomSkuPayload(); const newSku = await adminApi.skus.create('default', payload); @@ -18,14 +18,14 @@ test('Can create a new SKU', async (t) => { t.deepEqual(newSku.albums, payload.albums || []); }); -test('Can view SKU details', async (t) => { +test('[bvt] Can view SKU details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newSku = await adminApi.skus.create('default', $.randomSkuPayload()); const foundSku = await adminApi.skus.one('default', newSku.attributes.code.v); t.deepEqual(foundSku, newSku); }); -test('Can update SKU details', async (t) => { +test('[bvt] Can update SKU details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newSku = await adminApi.skus.create('default', $.randomSkuPayload()); const payload = $.randomSkuPayload(); @@ -37,7 +37,7 @@ test('Can update SKU details', async (t) => { t.deepEqual(updatedSku.albums, payload.albums || []); }); -test('Can archive a SKU', async (t) => { +test('[bvt] Can archive a SKU', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newSku = await adminApi.skus.create('default', $.randomSkuPayload()); const archivedSku = await adminApi.skus.archive('default', newSku.attributes.code.v); @@ -48,7 +48,7 @@ test('Can archive a SKU', async (t) => { t.deepEqual(archivedSku.context, newSku.context); }); -test('Can access the inventory', async (t) => { +test('[bvt] Can access the inventory', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newSku = await adminApi.skus.create('default', $.randomSkuPayload()); const inventory = await waitFor(500, 10000, () => adminApi.skus.inventory(newSku.attributes.code.v)); diff --git a/build-tests/tests/store-admin.test.js b/build-tests/tests/bvt/store-admin.test.js similarity index 75% rename from build-tests/tests/store-admin.test.js rename to build-tests/tests/bvt/store-admin.test.js index 26888d2cbb..4aee164734 100644 --- a/build-tests/tests/store-admin.test.js +++ b/build-tests/tests/bvt/store-admin.test.js @@ -1,12 +1,12 @@ -import test from '../helpers/test'; -import { AdminApi } from '../helpers/Api'; -import isNumber from '../helpers/isNumber'; -import isString from '../helpers/isString'; -import isArray from '../helpers/isArray'; -import isDate from '../helpers/isDate'; -import $ from '../payloads'; +import test from '../../helpers/test'; +import { AdminApi } from '../../helpers/Api'; +import isNumber from '../../helpers/isNumber'; +import isString from '../../helpers/isString'; +import isArray from '../../helpers/isArray'; +import isDate from '../../helpers/isDate'; +import $ from '../../payloads'; -test('Can list store admins', async (t) => { +test('[bvt] Can list store admins', async (t) => { const adminApi = await AdminApi.loggedIn(t); const storeAdmins = await adminApi.storeAdmins.list(); t.truthy(isArray(storeAdmins)); @@ -21,7 +21,7 @@ test('Can list store admins', async (t) => { } }); -test('Can view store admin details', async (t) => { +test('[bvt] Can view store admin details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const storeAdmins = await adminApi.storeAdmins.list(); const storeAdmin = await adminApi.storeAdmins.one(storeAdmins[0].id); @@ -31,7 +31,7 @@ test('Can view store admin details', async (t) => { t.truthy(isString(storeAdmin.state)); }); -test('Can create a new store admin', async (t) => { +test('[bvt] Can create a new store admin', async (t) => { const adminApi = await AdminApi.loggedIn(t); const payload = $.randomStoreAdminPayload(); const newStoreAdmin = await adminApi.storeAdmins.create(payload); @@ -41,7 +41,7 @@ test('Can create a new store admin', async (t) => { t.is(newStoreAdmin.email, payload.email); }); -test('Can update store admin details', async (t) => { +test('[bvt] Can update store admin details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newStoreAdmin = await adminApi.storeAdmins.create($.randomStoreAdminPayload()); const payload = $.randomStoreAdminPayload(); diff --git a/build-tests/tests/storefront.test.js b/build-tests/tests/bvt/storefront.test.js similarity index 77% rename from build-tests/tests/storefront.test.js rename to build-tests/tests/bvt/storefront.test.js index ff82fdfb2f..064aa6b9fd 100644 --- a/build-tests/tests/storefront.test.js +++ b/build-tests/tests/bvt/storefront.test.js @@ -1,34 +1,34 @@ import superagent from 'superagent'; -import test from '../helpers/test'; -import { AdminApi, CustomerApi } from '../helpers/Api'; -import $ from '../payloads'; -import config from '../config'; +import test from '../../helpers/test'; +import { AdminApi, CustomerApi } from '../../helpers/Api'; +import $ from '../../payloads'; +import config from '../../config'; for (const storefront of config.storefronts) { - test(`Can access ${storefront.name} storefront`, async (t) => { + test(`[bvt] Can access ${storefront.name} storefront`, async (t) => { const response = await superagent.get(storefront.url); t.is(response.status, 200); }); - test(`Can access ${storefront.name} login page`, async (t) => { + test(`[bvt] Can access ${storefront.name} login page`, async (t) => { const response = await superagent.get(`${storefront.url}/?auth=LOGIN`); t.is(response.status, 200); }); - test(`Can access ${storefront.name} sign up page`, async (t) => { + test(`[bvt] Can access ${storefront.name} sign up page`, async (t) => { const response = await superagent.get(`${storefront.url}/?auth=SIGNUP`); t.is(response.status, 200); }); if (storefront.aboutPagePath) { - test(`Can access ${storefront.name} "About Us" page`, async (t) => { + test(`[bvt] Can access ${storefront.name} "About Us" page`, async (t) => { const response = await superagent.get(`${storefront.url}/${storefront.aboutPagePath}`); t.is(response.status, 200); }); } for (const category of storefront.categories) { - test(`Can access ${storefront.name} category "${category}"`, async (t) => { + test(`[bvt] Can access ${storefront.name} category "${category}"`, async (t) => { const response = await superagent.get(`${storefront.url}/${encodeURIComponent(category)}`); t.is(response.status, 200); }); diff --git a/build-tests/tests/testNotes.js b/build-tests/tests/bvt/testNotes.js similarity index 79% rename from build-tests/tests/testNotes.js rename to build-tests/tests/bvt/testNotes.js index 2372c44e35..24a0a802f6 100644 --- a/build-tests/tests/testNotes.js +++ b/build-tests/tests/bvt/testNotes.js @@ -1,11 +1,11 @@ -import test from '../helpers/test'; -import { AdminApi } from '../helpers/Api'; -import $ from '../payloads'; -import isDate from '../helpers/isDate'; -import isArray from '../helpers/isArray'; +import test from '../../helpers/test'; +import { AdminApi } from '../../helpers/Api'; +import $ from '../../payloads'; +import isDate from '../../helpers/isDate'; +import isArray from '../../helpers/isArray'; export default ({ objectType, createObject, selectId = obj => obj.id }) => { - test('Can list notes', async (t) => { + test('[bvt] Can list notes', async (t) => { const adminApi = await AdminApi.loggedIn(t); await adminApi.auth.login($.adminEmail, $.adminPassword, $.adminOrg); const newObject = await createObject(adminApi); @@ -13,7 +13,7 @@ export default ({ objectType, createObject, selectId = obj => obj.id }) => { t.truthy(isArray(notes)); }); - test('Can create a new note', async (t) => { + test('[bvt] Can create a new note', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newObject = await createObject(adminApi); const payload = $.randomCreateNotePayload(); @@ -25,7 +25,7 @@ export default ({ objectType, createObject, selectId = obj => obj.id }) => { t.truthy(isDate(newNote.createdAt)); }); - test('Can update note details', async (t) => { + test('[bvt] Can update note details', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newObject = await createObject(adminApi); const newNote = await adminApi.notes.create(objectType, selectId(newObject), $.randomCreateNotePayload()); diff --git a/build-tests/tests/testWatchers.js b/build-tests/tests/bvt/testWatchers.js similarity index 85% rename from build-tests/tests/testWatchers.js rename to build-tests/tests/bvt/testWatchers.js index d3cd2d6d6b..c4395ab7cd 100644 --- a/build-tests/tests/testWatchers.js +++ b/build-tests/tests/bvt/testWatchers.js @@ -1,11 +1,11 @@ -import test from '../helpers/test'; -import { AdminApi } from '../helpers/Api'; -import $ from '../payloads'; -import isDate from '../helpers/isDate'; -import isArray from '../helpers/isArray'; +import test from '../../helpers/test'; +import { AdminApi } from '../../helpers/Api'; +import $ from '../../payloads'; +import isDate from '../../helpers/isDate'; +import isArray from '../../helpers/isArray'; export default ({ objectApi, createObject, selectId }) => { - test('Can list watchers', async (t) => { + test('[bvt] Can list watchers', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newObject = await createObject(adminApi); const id = selectId(newObject); @@ -14,7 +14,7 @@ export default ({ objectApi, createObject, selectId }) => { t.is(watchers.length, 0); }); - test('Can add watcher', async (t) => { + test('[bvt] Can add watcher', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newObject = await createObject(adminApi); const storeAdmins = await adminApi.storeAdmins.list(); @@ -32,7 +32,7 @@ export default ({ objectApi, createObject, selectId }) => { t.is(watchers[0].assignmentType, 'watcher'); }); - test('Can remove watcher', async (t) => { + test('[bvt] Can remove watcher', async (t) => { const adminApi = await AdminApi.loggedIn(t); const newObject = await createObject(adminApi); const storeAdmins = await adminApi.storeAdmins.list();