Skip to content

Commit 1519e21

Browse files
committed
test: add tests for login and namespace commands
Added tests for: - login: error with serverResponseCode extraction - namespace: empty NAMESPACE response attributes, default personal namespace when empty array, empty LIST attributes in fallback Improves login.js coverage from 93.54% to 100%. Improves namespace.js coverage from 94.39% to 100%.
1 parent b44f9b4 commit 1519e21

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

test/commands-integration-test.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,36 @@ module.exports['Commands: login handles error'] = async test => {
207207
test.done();
208208
};
209209

210+
module.exports['Commands: login error includes serverResponseCode'] = async test => {
211+
const connection = createMockConnection({
212+
state: 1,
213+
exec: async () => {
214+
const err = new Error('Auth failed');
215+
err.response = {
216+
tag: 'A1',
217+
command: 'NO',
218+
attributes: [
219+
{
220+
type: 'SECTION',
221+
section: [{ type: 'ATOM', value: 'AUTHENTICATIONFAILED' }]
222+
},
223+
{ type: 'TEXT', value: 'Authentication failed' }
224+
]
225+
};
226+
throw err;
227+
}
228+
});
229+
230+
try {
231+
await loginCommand(connection, 'testuser', 'wrongpass');
232+
test.ok(false, 'Should have thrown');
233+
} catch (err) {
234+
test.equal(err.authenticationFailed, true);
235+
test.equal(err.serverResponseCode, 'AUTHENTICATIONFAILED');
236+
}
237+
test.done();
238+
};
239+
210240
// ============================================
211241
// LOGOUT Command Tests
212242
// ============================================
@@ -6042,6 +6072,84 @@ module.exports['Commands: namespace fallback strips leading delimiter from prefi
60426072
test.done();
60436073
};
60446074

6075+
module.exports['Commands: namespace ignores empty NAMESPACE response attributes'] = async test => {
6076+
const connection = createMockConnection({
6077+
state: 2,
6078+
capabilities: new Map([['NAMESPACE', true]]),
6079+
exec: async (cmd, args, opts) => {
6080+
if (cmd === 'NAMESPACE' && opts && opts.untagged && opts.untagged.NAMESPACE) {
6081+
// Empty attributes - the callback should return early
6082+
await opts.untagged.NAMESPACE({
6083+
attributes: []
6084+
});
6085+
// Also provide a valid NAMESPACE to avoid error
6086+
await opts.untagged.NAMESPACE({
6087+
attributes: [[[{ value: 'INBOX.' }, { value: '.' }]], null, null]
6088+
});
6089+
}
6090+
return { next: () => {} };
6091+
}
6092+
});
6093+
6094+
const result = await namespaceCommand(connection);
6095+
// Should return namespace from the second call
6096+
test.equal(result.prefix, 'INBOX.');
6097+
test.equal(result.delimiter, '.');
6098+
test.done();
6099+
};
6100+
6101+
module.exports['Commands: namespace sets default when personal namespace is empty array'] = async test => {
6102+
const connection = createMockConnection({
6103+
state: 2,
6104+
capabilities: new Map([['NAMESPACE', true]]),
6105+
exec: async (cmd, args, opts) => {
6106+
if (cmd === 'NAMESPACE' && opts && opts.untagged && opts.untagged.NAMESPACE) {
6107+
// Provide an array where entries don't pass the filter
6108+
// (entry.length < 2), so getNamsepaceInfo returns []
6109+
await opts.untagged.NAMESPACE({
6110+
attributes: [
6111+
[[]], // array with one empty entry - filter removes it, returns []
6112+
null, // other
6113+
null // shared
6114+
]
6115+
});
6116+
}
6117+
return { next: () => {} };
6118+
}
6119+
});
6120+
6121+
const result = await namespaceCommand(connection);
6122+
// Should set default personal namespace when personal[0] is falsy
6123+
test.equal(result.prefix, '');
6124+
test.equal(result.delimiter, '.');
6125+
test.done();
6126+
};
6127+
6128+
module.exports['Commands: namespace fallback ignores empty LIST attributes'] = async test => {
6129+
let listCallCount = 0;
6130+
const connection = createMockConnection({
6131+
state: 2,
6132+
capabilities: new Map(), // No NAMESPACE capability
6133+
exec: async (cmd, args, opts) => {
6134+
if (cmd === 'LIST' && opts && opts.untagged && opts.untagged.LIST) {
6135+
listCallCount++;
6136+
// Empty attributes - the callback should return early
6137+
await opts.untagged.LIST({
6138+
attributes: []
6139+
});
6140+
}
6141+
return { next: () => {} };
6142+
}
6143+
});
6144+
6145+
const result = await namespaceCommand(connection);
6146+
test.ok(result);
6147+
test.equal(listCallCount, 1);
6148+
// With empty LIST, prefix and delimiter are undefined
6149+
test.equal(result.prefix, '');
6150+
test.done();
6151+
};
6152+
60456153
// ============================================
60466154
// QUOTA Command Tests
60476155
// ============================================

0 commit comments

Comments
 (0)