1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 12:01:57 +08:00
Sofia Calderon 7a22c9e85b
Refactoring apiConverts (#817)
* configured babel and jest to work with webpack

* added util function to camelize object entries

* added tests for apiconvert dashboard

* added enaming object key function

* finished refactoring of convertapi dashboard

* renamed camelize to transformObject

* renamed uuids to randomValues

* use random strings instead of hard coded values in test

* refactored dictionary.process and added tests

* refactored dashboard tests - test with json objects

* added first tests for apiConvert core

* made camelizeObjectkeys immutable

* added talismanrc to gitignore

* added all tests for apiConverts core

* added more dictionary tests

* finished refactoring apiConverts dictionary

* restructured objects in folders

* refactored apiConverts persistence

* refactored apiConvert pos

* refactored apiConvert privateAccess

* refactored apiConverts process

* refactored apiConverts report

* refactored apiConverts user

* refactored apiConverts values

* refactored apiConverts window

* linted all test files

* removed tests for privateAccess

* removed typos from prev implementation
2021-05-12 12:34:53 -04:00

175 lines
7.0 KiB
JavaScript

import {
convertContextInfo,
convertOrganization,
convertLanguage,
convertCountry,
convertBusinessPartner,
convertConversionRate,
convertBankAccount,
convertDocumentType,
convertDocumentStatus,
convertPriceList,
convertTaxRate,
convertProduct,
convertProductPrice
} from '@/utils/ADempiere/apiConverts/core.js'
import contextInfo from './objects/fromApi/contextInfo.json'
import convertedContextInfo from './objects/converted/contextInfo.json'
import contextInfoWithoutMessage from './objects/fromApi/contextInfoWithoutMessage.json'
import convertedContextInfoWithoutMessage from './objects/converted/contextInfoWithoutMessage.json'
import organization from './objects/fromApi/organization.json'
import convertedOrganization from './objects/converted/organization.json'
import language from './objects/fromApi/language.json'
import convertedLanguage from './objects/converted/language.json'
import country from './objects/fromApi/country.json'
import convertedCountry from './objects/converted/country.json'
import countryWithNoCurrency from './objects/fromApi/countryNoCurrency.json'
import convertedCountryWithNoCurrency from './objects/converted/countryNoCurrency.json'
import businessPartner from './objects/fromApi/businessPartner.json'
import convertedBusinessPartner from './objects/converted/businessPartner.json'
import conversionRate from './objects/fromApi/conversionRate.json'
import convertedConversionRate from './objects/converted/conversionRate.json'
import conversionRateNoCurrency from './objects/fromApi/conversionRateNoCurrency.json'
import convertedConversionRateNoCurrency from './objects/converted/conversionRateNoCurrency.json'
import salesRepresentative from './objects/fromApi/salesRepresentative.json'
import convertedSalesRepresentative from './objects/converted/salesRepresentative.json'
import bankAccount from './objects/fromApi/bankAccount.json'
import convertedBankAccount from './objects/converted/bankAccount.json'
import documentType from './objects/fromApi/documentType.json'
import convertedDocumentType from './objects/converted/documentType.json'
import documentStatus from './objects/fromApi/documentStatus.json'
import convertedDocumentStatus from './objects/converted/documentStatus.json'
import priceList from './objects/fromApi/priceList.json'
import convertedPriceList from './objects/converted/priceList.json'
import taxRate from './objects/fromApi/taxRate.json'
import convertedTaxRate from './objects/converted/taxRate.json'
import product from './objects/fromApi/product.json'
import convertedProduct from './objects/converted/product.json'
import productPrice from './objects/fromApi/productPrice.json'
import convertedProductPrice from './objects/converted/productPrice.json'
describe('context info', () => {
it('should return a converted context info', () => {
const actualContextInfo = convertContextInfo(contextInfo)
expect(actualContextInfo).toEqual(convertedContextInfo)
})
it('should return empty object for undefined context info', () => {
const actualContextInfo = convertContextInfo(null)
expect(actualContextInfo).toEqual({ messageText: {}})
})
it('should return a converted context info with an empty message', () => {
const actualContextInfo = convertContextInfo(contextInfoWithoutMessage)
expect(actualContextInfo).toEqual(convertedContextInfoWithoutMessage)
})
})
describe('organization', () => {
it('should return a converted organization object', () => {
const actualOrganization = convertOrganization(organization)
expect(actualOrganization).toEqual(convertedOrganization)
})
})
describe('language', () => {
it('should return a converted language object', () => {
const actualLanguage = convertLanguage(language)
expect(actualLanguage).toEqual(convertedLanguage)
})
})
describe('country', () => {
it('should return a converted country object with currency', () => {
const actualCountry = convertCountry(country)
expect(actualCountry).toEqual(convertedCountry)
})
it('should return a converted country object without currency', () => {
const actualCountry = convertCountry(countryWithNoCurrency)
expect(actualCountry).toEqual(convertedCountryWithNoCurrency)
})
})
describe('business partner', () => {
it('should return a converted business partner object', () => {
const actualBusinessPartner = convertBusinessPartner(businessPartner)
expect(actualBusinessPartner).toEqual(convertedBusinessPartner)
})
})
describe('conversion rate', () => {
it('should return a converted conversion rate object with currencies', () => {
const actualConversionRate = convertConversionRate(conversionRate)
expect(actualConversionRate).toEqual(convertedConversionRate)
})
it('should return a converted conversion rate object without currencies', () => {
const actualConversionRate = convertConversionRate(
conversionRateNoCurrency
)
expect(actualConversionRate).toEqual(convertedConversionRateNoCurrency)
})
})
describe('sales representative', () => {
it('should return a converted sales representative object', () => {
const actualSalesRep = convertBusinessPartner(salesRepresentative)
expect(actualSalesRep).toEqual(convertedSalesRepresentative)
})
})
describe('bank account', () => {
it('should return a converted bank account object', () => {
const actualBankAccount = convertBankAccount(bankAccount)
expect(actualBankAccount).toEqual(convertedBankAccount)
})
it('should return undefined', () => {
const actualBankAccount = convertBankAccount(null)
expect(actualBankAccount).toBeUndefined()
})
})
describe('document type', () => {
it('should return a converted document type object', () => {
const actualDocumentType = convertDocumentType(documentType)
expect(actualDocumentType).toEqual(convertedDocumentType)
})
it('should return undefined', () => {
const actualDocumentType = convertBankAccount(null)
expect(actualDocumentType).toBeUndefined()
})
})
describe('document status', () => {
it('should return a converted document status object', () => {
const actualDocumentStatus = convertDocumentStatus(documentStatus)
expect(actualDocumentStatus).toEqual(convertedDocumentStatus)
})
})
describe('price list', () => {
it('should return a converted price list object', () => {
const actualPriceList = convertPriceList(priceList)
expect(actualPriceList).toEqual(convertedPriceList)
})
})
describe('tax rate', () => {
it('should return a converted tax rate object', () => {
const actualTaxRate = convertTaxRate(taxRate)
expect(actualTaxRate).toEqual(convertedTaxRate)
})
})
describe('product', () => {
it('should return a converted product object', () => {
const actualProduct = convertProduct(product)
expect(actualProduct).toEqual(convertedProduct)
})
})
describe('product price', () => {
it('should return a converted product price object', () => {
const actualProductPrice = convertProductPrice(productPrice)
expect(actualProductPrice).toEqual(convertedProductPrice)
})
})