Skip to content

Commit

Permalink
Merge pull request #2 from felipelealdefaria/new-release-v1
Browse files Browse the repository at this point in the history
refactor: return boolean status and update unit tests
  • Loading branch information
felipelealdefaria authored May 4, 2021
2 parents 50ca493 + 05ae744 commit 9a75c2b
Show file tree
Hide file tree
Showing 32 changed files with 5,798 additions and 8,750 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"project": "./tsconfig-eslint.json"
},
"rules": {
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/comma-spacing": "off",
"@typescript-eslint/return-await": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-unused-vars": "off",
"no-redeclare": "off",
"import/export": "off",
"import/export": "off"
}
}
16 changes: 16 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on: [push]
name: Test

jobs:
test:
name: run test
runs-on: ubuntu-latest

steps:
- name: Experiments
uses: actions/checkout@v1

- name: MakeTest
run: |
npm install
npm run test:ci
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Felipe Leal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
94 changes: 83 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# Experiments Service

[![npm version](https://img.shields.io/npm/v/@felipelealdefaria/experiments-service)](https://github.com/felipelealdefaria/experiments-service)
[![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/@felipelealdefaria/experiments-service)](https://github.com/felipelealdefaria/experiments-service)
[![npm bundle minzipped size (minzipped)](https://img.shields.io/bundlephobia/minzip/@felipelealdefaria/experiments-service)](https://github.com/felipelealdefaria/experiments-service)
[![repo stars](https://img.shields.io/github/stars/felipelealdefaria/experiments-service)](https://github.com/felipelealdefaria/experiments-service)
[![repo license](https://img.shields.io/github/license/felipelealdefaria/experiments-service)](https://github.com/felipelealdefaria/experiments-service)

Experiments service for creating A/B tests using lib [sixpack-js](https://github.com/sixpack/sixpack-js).

### Requirements

Clone this repo [sixpack-docker](https://github.com/LucianoNMoreira/sixpack-docker-compose) and run:

```bash
docker-compose up
```
```bash
API URI: http://127.0.0.1:5000/
SIXPACK DASH: http://127.0.0.1:5001/
```

### Installation

```bash
Expand All @@ -11,33 +30,86 @@ npm i @felipelealdefaria/experiments-service

### Usage

```typescript
import experiment from '@felipelealdefaria/experiments-service'
```

**1) Initialize:**

```javascript
import { experiment } from '@felipelealdefaria/experiments-service'
This is required before any other methods can be called.

const session = await experiment.init({ baseUrl: string }): Promise<InitResponse>
```typescript
await experiment.init(params: InitParams): Promise<InitResponse>
```

```bash
InitParams:
- baseUrl: string
- timeout?: number (default: 8000)
```
```bash
InitResponse:
- session: unknown
- error?: boolean
- success?: boolean
- message?: string
```

**2) Experiment Participate:**

```javascript
const res = await experiment.participate({ session, experimentName: string, variationsName: string[], traffic?: number (default: 1) }): Promise<ParticipateResponse>
console.log(res) // { experimentName: string, alternativeName: string }
To start an experiment (test a/b).

```typescript
await experiment.participate(params: ParticipateParams) => Promise<ParticipateResponse>
```

```bash
ParticipateParams
- session: unknown
- traffic?: number (default: 1) // means 50% for each variable
- variationsName: string[]
- experimentName: string
```
```bash
ParticipateResponse
- alternativeName?: string | null
- experimentName?: string | null
- error?: boolean
- success?: boolean
- message?: string
```

**3) Experiment Convert:**

```javascript
convert({ session, experimentName: string, kpi?: string }): Promise<void>
To convert an experiment KPI.

```typescript
await convert(params: ConvertParams) => Promise<ConvertResponse>
```

```bash
ConvertParams
- kpi?: string
- session: unknown
- experimentName: string
}
```
```bash
ConvertResponse
- kpi?: string
- experimentName?: string
- alternativeName?: string
- error?: boolean
- success?: boolean
- message?: string
```

**4) A/B Test:**
**4) A/B Test with React.Js:**

```javascript
```typescript
return (
<>
{ res.alternativeName === 'variant_option'} ? <ComponentA /> : <ComponentB /> }
{ res?.alternativeName === 'variant_option'} ? <ComponentA /> : <ComponentB /> }
</>
)
```
Expand Down
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module.exports = {
roots: ['<rootDir>/src'],
testMatch: [
'<rootDir>/src/**/*.{spec, test}.{ts,tsx}',
'<rootDir>/src/**/__tests__/*.{spec, test}.{ts,tsx}'
],
collectCoverageFrom: [
'<rootDir>/src/**/*.{ts,tsx}',
'<rootDir>/src/**/*.ts',
'!**/*.d.ts'
],
coverageDirectory: 'coverage',
Expand Down
Loading

0 comments on commit 9a75c2b

Please sign in to comment.