agmission/server/tests/test_sprayStat_normalization.js

79 lines
2.2 KiB
JavaScript

/**
* Test sprayStat normalization in ApplicationDetail model
* Verifies that sprayStat values are normalized to 0, 1, or 3
* (SatLoc value 2 should be normalized to 1)
*/
require('./setup');
const { expect } = require('chai');
const mongoose = require('mongoose');
const ApplicationDetail = require('../model/application_detail');
describe('sprayStat Normalization', function() {
this.timeout(10000); // Increase timeout for DB operations
// Test the Mongoose setter directly by creating a test schema instance
it('should normalize sprayStat value 2 to 1', function() {
// Create a test document (not saved to DB)
// Create a new instance with sprayStat = 2
const doc = new ApplicationDetail({
lat: 40.7128,
lon: -74.0060,
sprayStat: 2,
fileId: new mongoose.Types.ObjectId()
});
// After construction, the setter should have normalized it
expect(doc.sprayStat).to.equal(1, 'sprayStat=2 should be normalized to 1');
});
it('should preserve sprayStat = 0', function() {
const doc = new ApplicationDetail({
lat: 40.7128,
lon: -74.0060,
sprayStat: 0,
fileId: new mongoose.Types.ObjectId()
});
expect(doc.sprayStat).to.equal(0);
});
it('should preserve sprayStat = 1', function() {
const doc = new ApplicationDetail({
lat: 40.7128,
lon: -74.0060,
sprayStat: 1,
fileId: new mongoose.Types.ObjectId()
});
expect(doc.sprayStat).to.equal(1);
});
it('should preserve sprayStat = 3 (segment marker)', function() {
const doc = new ApplicationDetail({
lat: 40.7128,
lon: -74.0060,
sprayStat: 3,
fileId: new mongoose.Types.ObjectId()
});
expect(doc.sprayStat).to.equal(3, 'sprayStat=3 should be preserved for segment markers');
});
it('should normalize any sprayStat > 1 (except 3) to 1', function() {
const testValues = [2, 4, 5, 100];
for (const val of testValues) {
const doc = new ApplicationDetail({
lat: 40.7128,
lon: -74.0060,
sprayStat: val,
fileId: new mongoose.Types.ObjectId()
});
expect(doc.sprayStat).to.equal(1, `sprayStat=${val} should be normalized to 1`);
}
});
});