cjwt
Version:
Casstime jwt middleware
85 lines (77 loc) • 1.38 kB
JavaScript
const CJWT = require('../index');
describe('cjwt constructor', () => {
it ('no options', (done) => {
try {
new CJWT();
done(new Error('不能new'));
} catch (e) {
done();
}
});
it('no secret', (done) => {
try {
new CJWT({});
done("can't new");
} catch (e) {
done();
}
});
it('no verifyOptions', (done) => {
try {
new CJWT({
secret: 'abc',
signOptions: {}
});
done("can't new");
} catch (e) {
done();
}
});
it('no signOptions', (done) => {
try {
new CJWT({
secret: 'abc',
verifyOptions: {}
});
done("can't new");
} catch (e) {
done();
}
});
it('secret error', (done) => {
try {
new CJWT({
secret: {},
verifyOptions: {},
signOptions: {}
});
done("can't new");
} catch (e) {
done();
}
});
it('string secret', (done) => {
try {
new CJWT({
secret: 'secret',
verifyOptions: {},
signOptions: {}
});
done();
} catch (e) {
done(e);
}
});
it('function secret', (done) => {
try {
new CJWT({
secret: () => Promise.resolve('secret'),
verifyOptions: {},
signOptions: {}
});
done();
} catch (e) {
done(e);
}
});
});