Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const mockFetch = html =>
fetchMock.mockResolvedValue({ json: () => Promise.resolve({ html }) });
it('loadExchangeData', async () => {
fetch.mockResolvedValue({
json() {
return { entities: exchanges };
}
});
let stub = sinon.stub(Exchange, 'import');
await service.loadExchangeData();
expect(stub.getCall(0).args[0]).toEqual(importExchanges);
});
});
it('loadIdAttributeTypes', async () => {
fetch.mockResolvedValue({
json() {
return { ID_Attributes: idAttributesTypes };
}
});
let stub = sinon.stub(IdAttributeType, 'import');
await service.loadIdAttributeTypes();
expect(stub.getCall(0).args[0]).toEqual(importIdAttributeTypes);
});
it('resolveSchemas', async () => {
it('loadRemote', async () => {
let testRepo = {
name: 'test',
idAttributes: []
};
let testUrl = 'https://test-url/repository.json';
fetch.mockResolvedValue({
status: 200,
json() {
return testRepo;
}
});
let res = await Repository.loadRemote(testUrl);
expect(res.url).toBe(testUrl);
expect(res.content).toEqual(testRepo);
expect(res.name).toEqual(testRepo.name);
});
it('loadPriceData', async () => {
const priceService = new PriceService();
let addStub = sinon.stub(TokenPrice, 'bulkAdd').resolves();
let editStub = sinon.stub(TokenPrice, 'bulkEdit').resolves();
sinon.stub(TokenPrice, 'findAll').resolves(existingPrices);
fetch.mockResolvedValue({
json() {
return externalPrices;
}
});
await priceService.loadPriceData();
expect(editStub.getCall(0).args).toEqual([toUpdate]);
expect(addStub.getCall(0).args).toEqual([toInsert]);
});
it('startUpdateData', async () => {
it('loadRemote', async () => {
let testScchema = {
test: 'test'
};
let testUrl = 'https://test-url/ui-schema.json';
fetch.mockResolvedValue({
status: 200,
json() {
return testScchema;
}
});
let res = await UiSchema.loadRemote(testUrl);
expect(res.url).toBe(testUrl);
expect(res.content).toEqual(testScchema);
});
beforeEach(() => {
service = new StakingService({ web3Service: web3ServiceMock });
fetch.mockResolvedValue({
json() {
return remoteConfig;
}
});
});
afterEach(() => {