~singpolyma/jmp-schemas

c9889dc62753ec1b33c3e0fd6050dd4d66fc6690 — Stephen Paul Weber a year ago 912b6b0
Do not charge for voicemail
2 files changed, 22 insertions(+), 1 deletions(-)

M deploy/cdr_with_charge.sql
M verify/cdr_with_charge.sql
M deploy/cdr_with_charge.sql => deploy/cdr_with_charge.sql +2 -1
@@ 9,7 9,8 @@ CREATE VIEW cdr_with_charge AS
	SELECT DISTINCT ON (cdr_id)
		cdr.*,
		rate,
		rate * ceiling(billsec / 60.0) AS charge
		(CASE WHEN cdr.disposition = 'VOICEMAIL' THEN 0
		ELSE rate * ceiling(billsec / 60.0) END) AS charge
	FROM
		cdr
		INNER JOIN customer_plans USING (customer_id)

M verify/cdr_with_charge.sql => verify/cdr_with_charge.sql +20 -0
@@ 4,4 4,24 @@ BEGIN;

SELECT rate, charge FROM cdr_with_charge;

INSERT INTO plan_log
	(customer_id, plan_name, date_range)
	VALUES
	('test', 'test_plan', tsrange(LOCALTIMESTAMP, LOCALTIMESTAMP + '10 seconds'));

INSERT INTO cdr
	(cdr_id, customer_id, start, billsec, disposition, tel)
	VALUES
	('test1', 'test', LOCALTIMESTAMP, 10000, 'VOICEMAIL', '+15551234567');

DO $$
DECLARE
	c numeric;
BEGIN
	SELECT charge INTO c FROM cdr_with_charge WHERE cdr_id='test1';
	IF c IS NULL or c <> 0 THEN
		RAISE EXCEPTION 'Expected VOICEMAIL to charge 0, but got: %', c;
	END IF;
END $$;

ROLLBACK;