# proxify-method

> Project for flexible extension of the existing functionality

Latest version **0.0.14** (published 2020-08-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install proxify-method
pnpm add proxify-method
yarn add proxify-method
bun add proxify-method
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.14 |
| Published | 2020-08-28 |
| First published | 2020-08-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12.18.3 |
| Dependencies | 0 |
| Unpacked size | 26.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Potapov Dmytro |
| Maintainers | potapovdim |
| Keywords | proxy object, proxify, flexible extension, extension, proxy method |

## Links

- npm: https://www.npmjs.com/package/proxify-method
- Repository: https://github.com/Simple-Automation-Testing/api-framework
- Homepage: https://github.com/Simple-Automation-Testing/api-framework#readme
- Issues: https://github.com/Simple-Automation-Testing/api-framework/issues
- npm.io page: https://npm.io/package/proxify-method

## Recent versions

- 0.0.14 (latest) — 2020-08-28
- 0.0.12 — 2020-08-28
- 0.0.11 — 2020-08-27
- 0.0.10 — 2020-08-27
- 0.0.9 — 2020-08-25
- 0.0.8 — 2020-08-25
- 0.0.7 — 2020-08-21
- 0.0.5 — 2020-08-15
- 0.0.4 — 2020-08-14
- 0.0.3 — 2020-08-11
- 0.0.2 — 2020-08-09
- 0.0.1 — 2020-08-08
- 0.0.1-a — 2020-08-07

## README

# proxify-method

## Zero dependencies package. Main purpose of this package is to provide integration of the common assertions into class methods without refactoring and updates of the class methods, this package does not affect constructor, getters/setters and does not affect internal logic of the class methods. Package works with async function/Promises, and also sync common code.

![npm downloads](https://img.shields.io/npm/dm/proxify-method.svg?style=flat-square)

### Usage

[ts example chainProxify](/example/example.ts)
[js example chainProxify](#js)

#### js

## chainProxify usage
```js
// example with node-fetch and chai
const fetch = require('node-fetch');
const {chainProxify} = require('proxify-method');
const {expect} = require('chai');

function assertResponseBody(expectedBodyTextPart, {response}) {
  expect(response).to.include(expectedBodyTextPart)
}

function assertResponseBodyStrictEqual(expectedBody, {response}) {
  expect(response).to.equal(bodyTextPart)
}

class ControllerIterface {
  constructor() {
    // this two assertions will be available for every method in this class
    chainProxify('assertBodyIncludes', assertResponseBody)
      .chainProxify('strictAssertBody', assertResponseBodyStrictEqual)
      .initContextChainModel(this);
  }

  getDataFromServerController() {
    return fetch('http://someurl.that.returns.some.data')
    .then(result => result.text())
    // this {response: result} object will be second argument of the assert functions
    .then(result => ({response: result}))
  }

  postDataFromServerController() {
    return fetch('http://someurl.that.should_receive.some.data', {method: 'POST', body: 'string data'})
    .then(result => result.text())
    // this {response: result} object will be second argument of the assert functions
    .then(result => ({response: result}))
  }
}


async function test() {
  const controller = new ControllerIterface();

  const expectedGetBodyPart = 'some string';
  const expectedGetBodyFull = 'some string full'
  // can be done like TDD
  const {response: responseTddExample} = await controller.getDataFromServerController();
  expect(responseTddExample).to.include(expectedGetBodyPart);
  expect(responseTddExample).to.equal(expectedGetBodyFull);
  // ... usage of the response
  const resultTdd = responseTddExample;

  // can be done like BDD
  const {response: responseBddExample} = await controller.getDataFromServerController()
    .assertBodyIncludes(expectedGetBodyPart)
    .strictAssertBody(expectedGetBodyFull)
  // ... usage of the response
  const resultBdd = responseBddExample;
}
```

## proxify usage
```ts
import {proxify} from 'proxify-method';

const obj = {a: 2, b: 3, c: 4};

function isPropExists(prop, value, targetObj) {
  expect(targetObj[prop]).toEqual(value);
}

const proxedObj = proxify(obj, {isPropExists: isPropExists});

const {a, b, c} = proxedObj
  .isPropExists('a', 2)
  .isPropExists('b', 3)
  .isPropExists('c', 4);

expect(a).toEqual(obj.a);
expect(b).toEqual(obj.b);
expect(c).toEqual(obj.c);
expect(proxedObj).toDeepEqual(obj);

```

---
_Source: https://npm.io/package/proxify-method · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
