-
Notifications
You must be signed in to change notification settings - Fork 5
Add member_for_more_than_three_years account attribute #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ const express = require('express'); | |||||||||||
| const config_router = require('../src/router_config.js').config_router; | ||||||||||||
| const nostr = require('nostr'); | ||||||||||||
| const current_time = require('../src/utils.js').current_time; | ||||||||||||
| const { get_account_info_payload } = require('../src/user_management.js'); | ||||||||||||
| const { supertest_client } = require('./controllers/utils.js'); | ||||||||||||
| const { v4: uuidv4 } = require('uuid') | ||||||||||||
|
|
||||||||||||
|
|
@@ -84,20 +85,112 @@ test('config_router - Account management routes', async (t) => { | |||||||||||
| .get('/accounts/abc123') | ||||||||||||
| .expect(200); | ||||||||||||
|
|
||||||||||||
| const expectedData = { | ||||||||||||
| pubkey: account_info.pubkey, | ||||||||||||
| created_at: account_info.created_at, | ||||||||||||
| subscriber_number: 1, | ||||||||||||
| expiry: account_info.expiry, | ||||||||||||
| active: true, | ||||||||||||
| testflight_url: null, | ||||||||||||
| attributes: { | ||||||||||||
| member_for_more_than_one_year: false | ||||||||||||
| } | ||||||||||||
| }; | ||||||||||||
| t.same(res.body, expectedData, 'Response should match expected value'); | ||||||||||||
| t.equal(res.body.pubkey, account_info.pubkey) | ||||||||||||
| t.equal(res.body.created_at, account_info.created_at) | ||||||||||||
| t.equal(res.body.subscriber_number, 1) | ||||||||||||
| t.equal(res.body.expiry, account_info.expiry) | ||||||||||||
| t.equal(res.body.active, true) | ||||||||||||
| t.equal(res.body.testflight_url, null) | ||||||||||||
| t.equal(res.body.attributes.member_for_more_than_one_year, false) | ||||||||||||
| // Legacy account with 30-day past + 30-day future expiry yields ~60 days of membership | ||||||||||||
| const sixty_days = 60 * 24 * 60 * 60 | ||||||||||||
| t.ok(res.body.attributes.active_membership_duration > sixty_days - 10, 'duration should be approximately 60 days') | ||||||||||||
| t.ok(res.body.attributes.active_membership_duration < sixty_days + 10, 'duration should be approximately 60 days') | ||||||||||||
| t.end(); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| t.end(); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| test('get_account_info_payload - membership tenure attributes', async (t) => { | ||||||||||||
| const one_year_in_seconds = 360 * 24 * 60 * 60 | ||||||||||||
| const thirty_days_in_seconds = 60 * 60 * 24 * 30 | ||||||||||||
|
|
||||||||||||
| t.test('new account returns duration and member_for_more_than_one_year false', async (t) => { | ||||||||||||
| const account = { | ||||||||||||
| pubkey: 'abc123', | ||||||||||||
| created_at: current_time() - thirty_days_in_seconds, | ||||||||||||
| expiry: current_time() + thirty_days_in_seconds, | ||||||||||||
| transactions: [{ | ||||||||||||
| type: 'iap', | ||||||||||||
| id: '1', | ||||||||||||
| start_date: current_time() - thirty_days_in_seconds, | ||||||||||||
| end_date: current_time() + thirty_days_in_seconds, | ||||||||||||
| purchased_date: current_time() - thirty_days_in_seconds, | ||||||||||||
| duration: null | ||||||||||||
| }] | ||||||||||||
| } | ||||||||||||
| const payload = get_account_info_payload(1, account) | ||||||||||||
| t.equal(payload.attributes.member_for_more_than_one_year, false) | ||||||||||||
| t.ok(payload.attributes.active_membership_duration > 0, 'duration should be positive for active account') | ||||||||||||
| t.ok(payload.attributes.active_membership_duration < one_year_in_seconds, 'duration should be less than one year') | ||||||||||||
| t.end() | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| t.test('account with > 3 years returns correct duration', async (t) => { | ||||||||||||
| const total_duration = 3 * one_year_in_seconds + 1 | ||||||||||||
| const account = { | ||||||||||||
| pubkey: 'abc123', | ||||||||||||
| created_at: current_time() - total_duration, | ||||||||||||
| expiry: current_time() + thirty_days_in_seconds, | ||||||||||||
| transactions: [{ | ||||||||||||
| type: 'iap', | ||||||||||||
| id: '1', | ||||||||||||
| start_date: current_time() - total_duration, | ||||||||||||
| end_date: current_time(), | ||||||||||||
| purchased_date: current_time() - total_duration, | ||||||||||||
| duration: null | ||||||||||||
| }] | ||||||||||||
| } | ||||||||||||
| const payload = get_account_info_payload(1, account) | ||||||||||||
| t.equal(payload.attributes.member_for_more_than_one_year, true) | ||||||||||||
| t.ok(payload.attributes.active_membership_duration > 3 * one_year_in_seconds, 'duration should exceed three years') | ||||||||||||
| t.end() | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| t.test('account with > 1 year but < 3 years returns correct duration', async (t) => { | ||||||||||||
| const total_duration = one_year_in_seconds + 1 | ||||||||||||
| const account = { | ||||||||||||
| pubkey: 'abc123', | ||||||||||||
| created_at: current_time() - total_duration, | ||||||||||||
| expiry: current_time() + thirty_days_in_seconds, | ||||||||||||
| transactions: [{ | ||||||||||||
| type: 'iap', | ||||||||||||
| id: '1', | ||||||||||||
| start_date: current_time() - total_duration, | ||||||||||||
| end_date: current_time(), | ||||||||||||
| purchased_date: current_time() - total_duration, | ||||||||||||
| duration: null | ||||||||||||
| }] | ||||||||||||
| } | ||||||||||||
| const payload = get_account_info_payload(1, account) | ||||||||||||
| t.equal(payload.attributes.member_for_more_than_one_year, true) | ||||||||||||
| t.ok(payload.attributes.active_membership_duration > one_year_in_seconds) | ||||||||||||
| t.ok(payload.attributes.active_membership_duration < 3 * one_year_in_seconds) | ||||||||||||
| t.end() | ||||||||||||
| }) | ||||||||||||
|
|
||||||||||||
| t.test('inactive account returns zero duration', async (t) => { | ||||||||||||
| const total_duration = 3 * one_year_in_seconds + 1 | ||||||||||||
| const account = { | ||||||||||||
| pubkey: 'abc123', | ||||||||||||
| created_at: current_time() - total_duration, | ||||||||||||
| expiry: current_time() - 1, // expired | ||||||||||||
| transactions: [{ | ||||||||||||
| type: 'iap', | ||||||||||||
| id: '1', | ||||||||||||
| start_date: current_time() - total_duration, | ||||||||||||
| end_date: current_time() - 1, | ||||||||||||
| purchased_date: current_time() - total_duration, | ||||||||||||
| duration: null | ||||||||||||
| }] | ||||||||||||
| } | ||||||||||||
| const payload = get_account_info_payload(1, account) | ||||||||||||
| t.equal(payload.active, false) | ||||||||||||
| t.equal(payload.attributes.member_for_more_than_one_year, false) | ||||||||||||
| t.equal(payload.attributes.active_membership_duration, 0) | ||||||||||||
| t.end() | ||||||||||||
| }) | ||||||||||||
|
Comment on lines
+109
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New test suite never asserts on All four sub-tests check Expected assertions per sub-test:
🐛 Proposed additions // new account test (~line 124)
t.equal(payload.attributes.member_for_more_than_one_year, false)
+ t.equal(payload.attributes.member_for_more_than_three_years, false)
// > 3 years test (~line 146)
t.equal(payload.attributes.member_for_more_than_one_year, true)
+ t.equal(payload.attributes.member_for_more_than_three_years, true)
// > 1 year but < 3 years test (~line 167)
t.equal(payload.attributes.member_for_more_than_one_year, true)
+ t.equal(payload.attributes.member_for_more_than_three_years, false)
// inactive account test (~line 190)
t.equal(payload.attributes.member_for_more_than_one_year, false)
+ t.equal(payload.attributes.member_for_more_than_three_years, false)🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| t.end() | ||||||||||||
| }); | ||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
member_for_more_than_three_yearsassertion in route testThe route test validates
member_for_more_than_one_yearbut never asserts on the newmember_for_more_than_three_yearsfield. Since the account is only ~30 days old, the expected value isfalse.🐛 Proposed fix
t.equal(res.body.attributes.member_for_more_than_one_year, false) + t.equal(res.body.attributes.member_for_more_than_three_years, false)📝 Committable suggestion
🤖 Prompt for AI Agents