it('parses a mix of results and errors', () => { const response = {"results":[{"series":[{"name":"m1","columns":["fieldKey"],"values":[["f1"],["f2"]]}]},{"error": "measurement not found: m2"}]}; const result = parseShowFieldKeys(response); expect(result.errors).to.eql(['measurement not found: m2']); expect(result.fieldSets).to.eql({ m1: ['f1', 'f2'], }); });
it('parses a single result', () => { const response = {"results":[{"series":[{"name":"m1","columns":["fieldKey"],"values":[["f1"],["f2"]]}]}]}; const result = parseShowFieldKeys(response); expect(result.errors).to.eql([]); expect(result.fieldSets).to.eql({ m1: ['f1', 'f2'], }); });
showFieldKeys(proxySource, database, measurement, retentionPolicy).then((resp) => { const {errors, fieldSets} = showFieldKeysParser(resp.data); if (errors.length) { // TODO: do something } this.setState({ fields: fieldSets[measurement].map((f) => { return {field: f, funcs: []}; }), }); });
it('parses multiple errors', () => { const response = {"results":[{"error": "measurement not found: m1"}, {"error": "measurement not found: m2"}]}; const result = parseShowFieldKeys(response); expect(result.errors).to.eql(['measurement not found: m1', 'measurement not found: m2']); expect(result.fieldSets).to.eql({}); });