All files / src/api/connector/external wordpress.js

62.96% Statements 17/27
25% Branches 1/4
70% Functions 7/10
65.38% Lines 17/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60                  4x 3x 3x     4x                                       1x   1x 1x 1x 1x       1x 1x     1x 1x       1x 1x 1x 1x        
/*
Connector to Wordpress implementation inside Chameleon Ride.
Use generic REST connector here when implemented.
Path: /connectors/wordpress
*/
import http from 'axios';
import { assign, toLower } from 'lodash';
import { getCommonMeta, getSavedSources } from '../common';
 
const getBaseUrl = (connector) => {
  const url = `${connector.options.endpoint}/${connector.name}`;
  return url;
};
 
const getChangeMethod = (options) => {
  const action = toLower(options.action);
  switch (action) {
    case 'delete':
      return action;
    default:
      return 'post';
  }
};
 
export default {
  changeSourceData(connector, source, options) {
    const url = `${getBaseUrl(connector.type)}/${source.name}`;
    const method = getChangeMethod(options);
    return http[method](url, assign(getCommonMeta(connector), options.payload)).then((response) => {
      const result = response.data;
      return result;
    });
  },
  getSources(connector, { savedOnly }) {
    Iif (savedOnly) return getSavedSources(connector);
 
    const url = getBaseUrl(connector.type);
    return http.get(url, getCommonMeta(connector)).then((response) => {
      const result = response.data;
      return result.sources;
    });
  },
  getSourceData(connector, source, options) {
    const url = `${getBaseUrl(connector.type)}/${source.name}`;
    return http.get(url, assign(getCommonMeta(connector), {
      params: options.params,
    })).then((response) => {
      const result = response.data;
      return result;
    });
  },
  getSourceSchema(connector, source) {
    const url = `${getBaseUrl(connector.type)}/${source.name}/schema`;
    return http.get(url, getCommonMeta(connector)).then((response) => {
      const result = response.data;
      return result;
    });
  },
};