Skip to content

Commit 75c97a6

Browse files
committed
snap
1 parent f91a9ae commit 75c97a6

2 files changed

Lines changed: 172 additions & 123 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Yaml Schema Testing Named numeric formats formatDescription for all format variants 1`] = `
4+
Object {
5+
"dimensions": Object {
6+
"created_at_time": Object {
7+
"currency": undefined,
8+
"format": undefined,
9+
"formatDescription": undefined,
10+
},
11+
"id_number_no_format": Object {
12+
"currency": undefined,
13+
"format": undefined,
14+
"formatDescription": Object {
15+
"name": "number",
16+
"specifier": ",.2f",
17+
},
18+
},
19+
"price_currency_1": Object {
20+
"currency": undefined,
21+
"format": Object {
22+
"alias": "currency_1",
23+
"type": "custom-numeric",
24+
"value": "$,.1f",
25+
},
26+
"formatDescription": Object {
27+
"name": "currency_1",
28+
"specifier": "$,.1f",
29+
},
30+
},
31+
"status_string": Object {
32+
"currency": undefined,
33+
"format": undefined,
34+
"formatDescription": undefined,
35+
},
36+
},
37+
"measures": Object {
38+
"balance_accounting_2": Object {
39+
"currency": undefined,
40+
"format": Object {
41+
"alias": "accounting_2",
42+
"type": "custom-numeric",
43+
"value": "(,.2f",
44+
},
45+
"formatDescription": Object {
46+
"name": "accounting_2",
47+
"specifier": "(,.2f",
48+
},
49+
},
50+
"bytes_abbr_3": Object {
51+
"currency": undefined,
52+
"format": Object {
53+
"alias": "abbr_3",
54+
"type": "custom-numeric",
55+
"value": ".3s",
56+
},
57+
"formatDescription": Object {
58+
"name": "abbr_3",
59+
"specifier": ".3s",
60+
},
61+
},
62+
"count_no_format": Object {
63+
"currency": undefined,
64+
"format": undefined,
65+
"formatDescription": Object {
66+
"name": "number",
67+
"specifier": ",.2f",
68+
},
69+
},
70+
"custom_amount_d3": Object {
71+
"currency": undefined,
72+
"format": Object {
73+
"type": "custom-numeric",
74+
"value": "$,.0f",
75+
},
76+
"formatDescription": Object {
77+
"name": "custom",
78+
"specifier": "$,.0f",
79+
},
80+
},
81+
"order_id_id": Object {
82+
"currency": undefined,
83+
"format": Object {
84+
"alias": "id",
85+
"type": "custom-numeric",
86+
"value": ".0f",
87+
},
88+
"formatDescription": Object {
89+
"name": "id",
90+
"specifier": ".0f",
91+
},
92+
},
93+
"rate_percent": Object {
94+
"currency": undefined,
95+
"format": "percent",
96+
"formatDescription": Object {
97+
"name": "percent",
98+
"specifier": ".2%",
99+
},
100+
},
101+
"revenue_currency": Object {
102+
"currency": "EUR",
103+
"format": "currency",
104+
"formatDescription": Object {
105+
"currency": "EUR",
106+
"name": "currency",
107+
"specifier": "$,.2f",
108+
},
109+
},
110+
"total_number": Object {
111+
"currency": undefined,
112+
"format": "number",
113+
"formatDescription": Object {
114+
"name": "number",
115+
"specifier": ",.2f",
116+
},
117+
},
118+
},
119+
}
120+
`;

packages/cubejs-schema-compiler/test/unit/yaml-schema.test.ts

Lines changed: 52 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ cubes:
10901090
expect(population!.format).toEqual({ type: 'custom-numeric', value: '.2s', alias: 'abbr' });
10911091
});
10921092

1093-
it('measure formatDescription with named format', async () => {
1093+
it('formatDescription for all format variants', async () => {
10941094
const { compiler, metaTransformer } = prepareYamlCompiler(`
10951095
cubes:
10961096
- name: Orders
@@ -1100,38 +1100,20 @@ cubes:
11001100
sql: id
11011101
type: number
11021102
primary_key: true
1103-
measures:
1104-
- name: total_amount
1105-
sql: amount
1106-
type: sum
1107-
format: accounting_2
1108-
- name: bytes
1109-
sql: bytes
1110-
type: sum
1111-
format: abbr_3
1112-
`);
1113-
1114-
await compiler.compile();
1115-
1116-
const { measures } = metaTransformer.cubes[0].config;
1117-
const totalAmount = measures.find((m) => m.name === 'Orders.total_amount');
1118-
expect(totalAmount!.formatDescription).toEqual({ name: 'accounting_2', specifier: '(,.2f' });
1119-
1120-
const bytes = measures.find((m) => m.name === 'Orders.bytes');
1121-
expect(bytes!.formatDescription).toEqual({ name: 'abbr_3', specifier: '.3s' });
1122-
});
1123-
1124-
it('measure formatDescription with standard format and currency', async () => {
1125-
const { compiler, metaTransformer } = prepareYamlCompiler(`
1126-
cubes:
1127-
- name: Orders
1128-
sql: "select * from tbl"
1129-
dimensions:
1130-
- name: id
1131-
sql: id
1103+
- name: price
1104+
sql: price
11321105
type: number
1133-
primary_key: true
1106+
format: currency_1
1107+
- name: status
1108+
sql: status
1109+
type: string
1110+
- name: created_at
1111+
sql: created_at
1112+
type: time
11341113
measures:
1114+
- name: count
1115+
sql: id
1116+
type: count
11351117
- name: revenue
11361118
sql: amount
11371119
type: sum
@@ -1141,108 +1123,55 @@ cubes:
11411123
sql: rate
11421124
type: number
11431125
format: percent
1144-
- name: count
1145-
sql: id
1146-
type: count
1147-
`);
1148-
1149-
await compiler.compile();
1150-
1151-
const { measures } = metaTransformer.cubes[0].config;
1152-
const revenue = measures.find((m) => m.name === 'Orders.revenue');
1153-
expect(revenue!.formatDescription).toEqual({ name: 'currency', specifier: '$,.2f', currency: 'EUR' });
1154-
1155-
const rate = measures.find((m) => m.name === 'Orders.rate');
1156-
expect(rate!.formatDescription).toEqual({ name: 'percent', specifier: '.2%' });
1157-
1158-
const count = measures.find((m) => m.name === 'Orders.count');
1159-
expect(count!.formatDescription).toEqual({ name: 'number', specifier: ',.2f' });
1160-
});
1161-
1162-
it('measure formatDescription with custom d3 specifier', async () => {
1163-
const { compiler, metaTransformer } = prepareYamlCompiler(`
1164-
cubes:
1165-
- name: Orders
1166-
sql: "select * from tbl"
1167-
dimensions:
1168-
- name: id
1169-
sql: id
1170-
type: number
1171-
primary_key: true
1172-
measures:
1173-
- name: total_amount
1126+
- name: total
11741127
sql: amount
11751128
type: sum
1176-
format: "$,.0f"
1177-
`);
1178-
1179-
await compiler.compile();
1180-
1181-
const { measures } = metaTransformer.cubes[0].config;
1182-
const totalAmount = measures.find((m) => m.name === 'Orders.total_amount');
1183-
expect(totalAmount!.formatDescription).toEqual({ name: 'custom', specifier: '$,.0f' });
1184-
});
1185-
1186-
it('dimension formatDescription only for number type', async () => {
1187-
const { compiler, metaTransformer } = prepareYamlCompiler(`
1188-
cubes:
1189-
- name: Orders
1190-
sql: "select * from tbl"
1191-
dimensions:
1192-
- name: id
1193-
sql: id
1194-
type: number
1195-
primary_key: true
1196-
- name: price
1197-
sql: price
1198-
type: number
1199-
format: currency_1
1200-
- name: status
1201-
sql: status
1202-
type: string
1203-
- name: created_at
1204-
sql: created_at
1205-
type: time
1206-
`);
1207-
1208-
await compiler.compile();
1209-
1210-
const { dimensions } = metaTransformer.cubes[0].config;
1211-
const price = dimensions.find((d) => d.name === 'Orders.price');
1212-
expect(price!.formatDescription).toEqual({ name: 'currency_1', specifier: '$,.1f' });
1213-
1214-
const status = dimensions.find((d) => d.name === 'Orders.status');
1215-
expect(status!.formatDescription).toBeUndefined();
1216-
1217-
const createdAt = dimensions.find((d) => d.name === 'Orders.created_at');
1218-
expect(createdAt!.formatDescription).toBeUndefined();
1219-
1220-
const id = dimensions.find((d) => d.name === 'Orders.id');
1221-
expect(id!.formatDescription).toEqual({ name: 'number', specifier: ',.2f' });
1222-
});
1223-
1224-
it('measure formatDescription with id format', async () => {
1225-
const { compiler, metaTransformer } = prepareYamlCompiler(`
1226-
cubes:
1227-
- name: Orders
1228-
sql: "select * from tbl"
1229-
dimensions:
1230-
- name: id
1231-
sql: id
1232-
type: number
1233-
primary_key: true
1234-
measures:
1129+
format: number
1130+
- name: bytes
1131+
sql: bytes
1132+
type: sum
1133+
format: abbr_3
1134+
- name: balance
1135+
sql: balance
1136+
type: sum
1137+
format: accounting_2
12351138
- name: order_id
12361139
sql: id
12371140
type: number
12381141
format: id
1142+
- name: custom_amount
1143+
sql: amount
1144+
type: sum
1145+
format: "$,.0f"
12391146
`);
12401147

12411148
await compiler.compile();
12421149

1243-
const { measures } = metaTransformer.cubes[0].config;
1244-
const orderId = measures.find((m) => m.name === 'Orders.order_id');
1245-
expect(orderId!.formatDescription).toEqual({ name: 'id', specifier: '.0f' });
1150+
const { measures, dimensions } = metaTransformer.cubes[0].config;
1151+
1152+
const pick = (list: any[], name: string) => {
1153+
const m = list.find((x) => x.name === name);
1154+
return { format: m?.format, formatDescription: m?.formatDescription, currency: m?.currency };
1155+
};
1156+
1157+
expect({
1158+
measures: {
1159+
count_no_format: pick(measures, 'Orders.count'),
1160+
revenue_currency: pick(measures, 'Orders.revenue'),
1161+
rate_percent: pick(measures, 'Orders.rate'),
1162+
total_number: pick(measures, 'Orders.total'),
1163+
bytes_abbr_3: pick(measures, 'Orders.bytes'),
1164+
balance_accounting_2: pick(measures, 'Orders.balance'),
1165+
order_id_id: pick(measures, 'Orders.order_id'),
1166+
custom_amount_d3: pick(measures, 'Orders.custom_amount'),
1167+
},
1168+
dimensions: {
1169+
id_number_no_format: pick(dimensions, 'Orders.id'),
1170+
price_currency_1: pick(dimensions, 'Orders.price'),
1171+
status_string: pick(dimensions, 'Orders.status'),
1172+
created_at_time: pick(dimensions, 'Orders.created_at'),
1173+
},
1174+
}).toMatchSnapshot();
12461175
});
12471176

12481177
it('invalid named format in YAML - error', async () => {

0 commit comments

Comments
 (0)