Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/dk/cvr.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { validate, format } from './cvr';
import { InvalidLength, InvalidChecksum } from '../exceptions';
import { InvalidLength, InvalidChecksum, InvalidFormat } from '../exceptions';

describe('dk/cvr', () => {
it('format:DK 13585628', () => {
Expand Down Expand Up @@ -31,4 +31,19 @@ describe('dk/cvr', () => {

expect(result.error).toBeInstanceOf(InvalidChecksum);
});

// No CVR number starts with 0. These all pass the modulus 11 check, so the
// leading digit is the only thing that rejects them.
test.each(['00000000', 'DK00000000', '01000004'])('validate:%s', value => {
const result = validate(value);

expect(result.error).toBeInstanceOf(InvalidFormat);
});

// A registered CVR number still passes.
test.each(['24256790', 'DK24256790'])('validate:%s', value => {
const result = validate(value);

expect(result.isValid && result.compact).toEqual('24256790');
});
});
2 changes: 1 addition & 1 deletion src/dk/cvr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const impl: Validator = {
if (value.length !== 8) {
return { isValid: false, error: new exceptions.InvalidLength() };
}
if (!strings.isdigits(value)) {
if (!strings.isdigits(value) || value[0] === '0') {
return { isValid: false, error: new exceptions.InvalidFormat() };
}

Expand Down