All files / fabric-contract-api/lib/annotations default.js

100% Statements 14/14
100% Branches 2/2
100% Functions 2/2
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33            2x 2x 2x   2x   2x 2x   2x   2x   2x 1x     1x   1x   1x   1x      
/*
 * Copyright IBM Corp. All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */
 
const Logger = require('../logger');
const logger = Logger.getLogger('./lib/annotations/default.js');
require('reflect-metadata');
 
module.exports.Default = function Default () {
 
    return (target) => {
        logger.info('@Default args:', 'Target ->', target.name);
 
        let dflt = Reflect.getMetadata('fabric:default', global);
 
        logger.debug('Existing fabric:default', dflt);
 
        if (dflt) {
            throw new Error('A default has already been specified');
        }
 
        const contract = new(target);
 
        dflt = contract.getName();
 
        Reflect.defineMetadata('fabric:default', dflt, global);
 
        logger.debug('Updated fabric:default', dflt);
    };
};