Skip to content

Instantly share code, notes, and snippets.

@wcdz
Last active August 6, 2022 05:31
Show Gist options
  • Save wcdz/af31c4f6d5b9fab5f27b9c44dbd82fb7 to your computer and use it in GitHub Desktop.
Save wcdz/af31c4f6d5b9fab5f27b9c44dbd82fb7 to your computer and use it in GitHub Desktop.
import axios from 'axios'
import { config } from 'dotenv'
config();
export class EasyBroker {
get paramsEasyBroker() {
return { 'page': 1, 'limit': 50, } // La documentacion indica que el maximo de objetos es 50
}
get headersEasyBroker() {
return { 'X-Authorization': process.env.EasyBroker_KEY || 'l7u502p8v46ba3ppgvj5y2aad50lb9' }
}
public async title() {
try {
const instance = axios.create({
baseURL: 'https://api.stagingeb.com/v1',
params: this.paramsEasyBroker,
headers: this.headersEasyBroker
});
const resp = await instance.get('/properties');
return resp.data.content;
} catch (error) {
console.error(error);
return [];
}
}
}
(async () => {
const easyBroker: EasyBroker = new EasyBroker();
const titles = await easyBroker.title();
console.log(titles); // Para ver las propiedades que me da el API
console.log('\n\n--------TITLES--------\n');
titles.forEach((t: any, i: number) => {
console.log(`${(i + 1)}. ${t.title}`);
});
})();
import { EasyBroker } from "./App";
const easyBroker: EasyBroker = new EasyBroker();
const expetedVerify = async () => {
const data: [{}] = await easyBroker.title();
return data.forEach((t: any) => t.title);
}
const resultVerify = async () => {
const titles: [{}] = await easyBroker.title();
return titles.forEach((t: any) => t.title);
}
describe('GET - EasyBroker', () => {
test('Probando el metodo title()', async () => {
const expeted = await expetedVerify();
const result = await resultVerify();
expect(result).toStrictEqual(expeted);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment