~singpolyma/jmp-schemas

jmp-schemas/verify/cdr_charge.sql -rw-r--r-- 1.1 KiB
395bb797Stephen Paul Weber Tag for notify on top up an expired account a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- Verify jmp:cdr_charge on pg

BEGIN;

INSERT INTO plans VALUES ('{
	"name": "test",
	"minutes": { "included": 10440 }
}');

INSERT INTO call_rates (prefix, direction, plan_name, rate)
	VALUES('+1', 'outbound', 'test', 0.0087);

INSERT INTO plan_log (customer_id, plan_name, date_range)
	VALUES('test', 'test', TSRANGE(LOCALTIMESTAMP, LOCALTIMESTAMP + '5 minutes'));

DO $$
DECLARE
	n numeric;
BEGIN
	SELECT cdr_charge(localtimestamp, 'test', 0.0087, 1) INTO n;

	IF n IS NULL OR n <> 0 THEN
		RAISE EXCEPTION 'Expected 0, got: %', n;
	END IF;

	SELECT cdr_charge(localtimestamp, 'test', 0.0087, 2) INTO n;

	IF n IS NULL OR n <> 0 THEN
		RAISE EXCEPTION 'Expected 0, got: %', n;
	END IF;
END $$;

INSERT INTO cdr (cdr_id, customer_id, start, billsec, disposition, tel) VALUES(
	'test1',
	'test',
	LOCALTIMESTAMP - MAKE_INTERVAL(secs := 10),
	20000,
	'ANSWERED',
	'+15551234567'
);

DO $$
DECLARE
	n numeric;
BEGIN
	SELECT cdr_charge(localtimestamp, 'test', 0.0087, 100) INTO n;

	IF n IS NULL OR n <> 100 THEN
		RAISE EXCEPTION 'Expected 100, got: %', n;
	END IF;
END $$;

ROLLBACK;