Automated Action 545563e776 Implement comprehensive real-time chat API with NestJS
- Complete NestJS TypeScript implementation with WebSocket support
- Direct messaging (DM) and group chat functionality
- End-to-end encryption with AES encryption and key pairs
- Media file support (images, videos, audio, documents) up to 100MB
- Push notifications with Firebase Cloud Messaging integration
- Mention alerts and real-time typing indicators
- User authentication with JWT and Passport
- SQLite database with TypeORM entities and relationships
- Comprehensive API documentation with Swagger/OpenAPI
- File upload handling with secure access control
- Online/offline status tracking and presence management
- Message editing, deletion, and reply functionality
- Notification management with automatic cleanup
- Health check endpoint for monitoring
- CORS configuration for cross-origin requests
- Environment-based configuration management
- Structured for Flutter SDK integration

Features implemented:
 Real-time messaging with Socket.IO
 User registration and authentication
 Direct messages and group chats
 Media file uploads and management
 End-to-end encryption
 Push notifications
 Mention alerts
 Typing indicators
 Message read receipts
 Online status tracking
 File access control
 Comprehensive API documentation

Ready for Flutter SDK development and production deployment.
2025-06-21 17:13:05 +00:00

205 lines
5.9 KiB
JavaScript

var memoizer = require('./..');
var assert = require('chai').assert;
describe('lru-memoizer (itemMaxAge)', function () {
var loadTimes = 0, memoized;
beforeEach(function () {
loadTimes = 0;
});
it('should use default behavior if not configured', function (done) {
memoized = memoizer({
load: function (a, b, callback) {
loadTimes++;
setTimeout(function () {
callback(null, a + b);
}, 100);
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10,
maxAge: 500
});
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Not expired yet.
setTimeout(function() {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Expired, load times will increase.
setTimeout(function() {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 2);
done();
});
}, 200);
});
}, 400);
});
});
it('should return all args and the result in the itemMaxAge function', function (done) {
var args;
memoized = memoizer({
load: function (a, b, callback) {
loadTimes++;
setTimeout(function () {
callback(null, a + b);
}, 100);
},
itemMaxAge: function (a, b, result) {
args = arguments;
return 1000;
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10,
maxAge: 600
});
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(args[0], 1);
assert.strictEqual(args[1], 2);
assert.strictEqual(args[2], 3);
done();
});
});
it('should overwrite the default behavior if configured', function (done) {
var maxAge = 0;
var lastKey = null;
memoized = memoizer({
load: function (a, b, callback) {
loadTimes++;
setTimeout(function () {
callback(null, a + b);
}, 100);
},
itemMaxAge: function (a, b, result) {
lastKey = a + '-' + b;
// In this test, we set the maxAge of the current item to (result*100).
// If the result is 3, the max age of this item will be 300.
maxAge = result * 100;
return maxAge;
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10,
maxAge: 600
});
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Not expired yet after 200 ms, because the expiration is 300
setTimeout(function() {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Expired because now we are at 350 ms (even though gloabl expiration has been set to 600)
setTimeout(function() {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 2);
// Expired again, because 350ms have passed again.
setTimeout(function() {
memoized(1,2, function (err, result) {
assert.isNull(err);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 3);
done();
});
}, 350);
});
}, 150);
});
}, 200);
});
});
it('should overwrite the default behavior if configured (sync)', function (done) {
var maxAge = 0;
var lastKey = null;
memoized = memoizer.sync({
load: function (a, b) {
loadTimes++;
return a + b;
},
itemMaxAge: function (a, b, result) {
lastKey = a + '-' + b;
// In this test, we set the maxAge of the current item to (result*100).
// If the result is 3, the max age of this item will be 300.
maxAge = result * 100;
return maxAge;
},
hash: function (a, b) {
return a + '-' + b;
},
max: 10,
maxAge: 600
});
var result = memoized(1, 2);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Not expired yet after 200 ms, because the expiration is 300
setTimeout(function() {
result = memoized(1, 2);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 1);
// Expired because now we are at 350 ms (even though gloabl expiration has been set to 600)
setTimeout(function() {
result = memoized(1,2);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 2);
// Expired again, because 350ms have passed again.
setTimeout(function() {
result = memoized(1,2);
assert.strictEqual(maxAge, 300);
assert.strictEqual(lastKey, '1-2');
assert.strictEqual(result, 3);
assert.strictEqual(loadTimes, 3);
done();
}, 350);
}, 150);
}, 200);
});
});